Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should attachShadow throw or override when an existing declarative shadow root doesn't match? #1235

Closed
emilio opened this issue Nov 26, 2023 · 18 comments · Fixed by #1246
Closed
Labels
topic: shadow Relates to shadow trees (as defined in DOM)

Comments

@emilio
Copy link
Contributor

emilio commented Nov 26, 2023

What is the issue with the DOM Standard?

See also #1234 which involves the same code-paths.

I find it really weird / confusing that calling .attachShadow({ mode: "closed" }) on an element that has an open declarative shadow DOM just silently returns the open shadow DOM.

It might be even more problematic the other way around. .attachShadow({ mode: "open" }) on a closed declarative shadow host will just happily return a reference to an otherwise closed shadow root.

Same for the delegatesFocus flags and so on, probably the imperative flag should override these, at least, or maybe we should throw if the ShadowRootInit members don't match the declarative shadow DOM attributes...

Is that intentional? If it is it might at least be worth a note.

@emilio emilio changed the title Should attachShadow throw or override when an existing declarative shadow root doesn't match Should attachShadow throw or override when an existing declarative shadow root doesn't match? Nov 26, 2023
@emilio
Copy link
Contributor Author

emilio commented Nov 27, 2023

(Forgot the ccs, hah)

cc @mfreed7 @rniwa @annevk @avandolder

@mfreed7
Copy link
Contributor

mfreed7 commented Nov 27, 2023

I did think about this one. The important detail (to me at least) is that attachShadow in these cases will clear out the shadow root before returning it. So it's not like this is an end-run around revealing closed shadow root content or anything. It's just a weird way to create a closed shadow root via a call to attachShadow({mode:'open'}).

I do agree that it's perhaps a bit odd that the options provided to attachShadow don't get respected in this case, but the alternative seemed worse to me: changing the flags on an already-existing shadow root as a result of this call. I'm open to suggestions. (Keeping in mind that several implementations have shipped.)

@emilio
Copy link
Contributor Author

emilio commented Nov 27, 2023

I don't know, that makes code like this potentially fail in a very action-at-a-distance way, and with no pointer to the root cause of the issue (a shadowrootmode=closed template):

host.attachShadow({ mode: "open" });
host.shadowRoot.appendChild(...);

I guess we could add a console warning or so... Maybe it's worth a note in the spec?

@annevk
Copy link
Member

annevk commented Nov 28, 2023

Why did we not throw again?

I'm also not sure I understand

This means that if multiple declarative shadow roots are contained within a single shadow host, only the last one will remain.

upon rereading. How could a host ever have multiple shadow roots?

@emilio
Copy link
Contributor Author

emilio commented Nov 28, 2023

You'd have multiple <template> elements as children.

@annevk
Copy link
Member

annevk commented Nov 28, 2023

Okay, but those are not necessarily declarative shadow roots. Only one of them can be. Might just be a matter of using more precise wording then.

@mfreed7
Copy link
Contributor

mfreed7 commented Nov 28, 2023

I don't know, that makes code like this potentially fail in a very action-at-a-distance way, and with no pointer to the root cause of the issue (a shadowrootmode=closed template):

That's true. But typically this (DSD) is already "action at a distance" by definition, since it's rendered on the server.

I guess we could add a console warning or so... Maybe it's worth a note in the spec?

This makes a lot of sense - the console warning. I think I'll add that to Chromium. Do we add notes about console warnings to the spec?

Why did we not throw again?

Not throwing is an important backwards-compatibility behavior, which is the entire point for this whole "empty and return the root" behavior. If a component was built without SSR/DSD knowledge, and then some server code decides to SSR that component, we didn't want to break the component. The only real way to do that is to keep attachShadow() working roughly as intended.

Importantly, if the server is taking a component that calls attachShadow({mode:'open'}) and converting that into a <template shadowrootmode=closed>, then that server is already very broken. So I don't think the "change the parameters" issue is really an issue in practice. Plus, components that understand SSD/DSD will check for a .shadowRoot and won't ever call attachShadow().

Okay, but those are not necessarily declarative shadow roots. Only one of them can be. Might just be a matter of using more precise wording then.

I agree that the wording is kind of hard to understand here. Perhaps instead of "declarative shadow roots" in that sentence, we should just use "<template shadowrootmode>'s" or something?

@emilio
Copy link
Contributor Author

emilio commented Nov 28, 2023

I think the ideal behaviour here would be to throw only if the init parameters are mismatched. Alternatively current behaviour and console warning, and probably note on the spec. But I find the current behaviour rather unfortunate

@mfreed7
Copy link
Contributor

mfreed7 commented Nov 28, 2023

I think the ideal behaviour here would be to throw only if the init parameters are mismatched. Alternatively current behaviour and console warning, and probably note on the spec. But I find the current behaviour rather unfortunate

I think I could live with that (throw if parameters mismatch). I'm assuming this won't be much of a breaking change.

Are you suggesting we check all parameters, such as delegatesFocus, slotAssignment, etc.?

@annevk
Copy link
Member

annevk commented Nov 28, 2023

For the wording issue: yes,

template elements whose shadowrootmode attribute is appropriately set

would work I think.

@emilio having to check for all the parameters and remember to do so when we add new parameters seems like a pain, but I guess we could do it. In retrospect I'm not sure we should have supported this scenario, but it's probably too late to completely change it.

@emilio
Copy link
Contributor Author

emilio commented Nov 28, 2023

Are you suggesting we check all parameters, such as delegatesFocus, slotAssignment, etc.?

Yes, otherwise they get silently ignored...

@mfreed7
Copy link
Contributor

mfreed7 commented Jan 9, 2024

I was getting started thinking about this change, and another case comes up. What should happen here?

<div>
  <template shadowrootmode=open>Root 1</template>
  <template shadowrootmode=closed>Root 2</template>
</div>

In current behavior and spec, there will be an open shadow root attached which contains "Root 2", because the "attach a shadow root" algorithm will clear out the first (open) root and insert "Root 2". We can't throw in the parser. Should this just be the console warning case?

@rniwa
Copy link
Collaborator

rniwa commented Jan 9, 2024

It seems like the first template should win in this case.

@annevk
Copy link
Member

annevk commented Jan 10, 2024

@rniwa I guess what you are suggesting is that the HTML parser completely ignores subsequent shadowrootmode template elements?

What does the parser do when a script attached a shadow root?

@mfreed7
Copy link
Contributor

mfreed7 commented Jan 11, 2024

It seems like the first template should win in this case.
@rniwa I guess what you are suggesting is that the HTML parser completely ignores subsequent shadowrootmode template elements?

I suppose that could work, presuming you mean always ignore subsequent declarative shadow roots, not just when their parameters mismatch. It's a change in behavior, so it might not be web compatible, but it seems relatively safe. If it sounds like you're happy with that, I'll try to implement it and see what happens.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 12, 2024
Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

[1] whatwg/dom#1235

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 12, 2024
Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

[1] whatwg/dom#1235

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 12, 2024
Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

[1] whatwg/dom#1235

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 12, 2024
Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

[1] whatwg/dom#1235

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 13, 2024
Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

[1] whatwg/dom#1235

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 16, 2024
Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

[1] whatwg/dom#1235

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
mfreed7 added a commit to mfreed7/html that referenced this issue Jan 16, 2024
Per the discussion at whatwg/dom#1235, this PR makes the *first* declarative shadow root "win". Prior behavior was for the *last* one to remain, but this PR changes second and subsequent declarative shadow roots to report an exception instead.
mfreed7 added a commit to mfreed7/dom that referenced this issue Jan 16, 2024
Per the discussion at whatwg#1235, this PR changes the behavior when calling `attachShadow()` on a node with an existing declarative shadow root. Now, if the parameters do not match between the arguments to `attachShadow()` and the existing root, throw an exception. Prior behavior was to silently return the declarative root as-is, with mismatched parameters.
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 16, 2024
Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

See [2] and [3] for the corresponding spec PRs.

[1] whatwg/dom#1235
[2] whatwg/html#10069
[3] whatwg/dom#1246

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 18, 2024
Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

See [2] and [3] for the corresponding spec PRs.

[1] whatwg/dom#1235
[2] whatwg/html#10069
[3] whatwg/dom#1246

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 18, 2024
Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

See [2] and [3] for the corresponding spec PRs.

[1] whatwg/dom#1235
[2] whatwg/html#10069
[3] whatwg/dom#1246

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
@mfreed7
Copy link
Contributor

mfreed7 commented Jan 18, 2024

I suppose that could work, presuming you mean always ignore subsequent declarative shadow roots, not just when their parameters mismatch. It's a change in behavior, so it might not be web compatible, but it seems relatively safe. If it sounds like you're happy with that, I'll try to implement it and see what happens.

Hearing no objections, I went ahead and implemented this in Chromium, and changed/added some WPTs. I also put up a corresponding set of HTML/DOM spec PRs. To summarize the changes:

  1. If two declarative shadow roots are included within a single host element, only the first one will remain. This is a change in behavior from before, but it hopefully won't encounter compat issues (TBD).
  2. If attachShadow() is used on an existing declarative shadow root, and the parameters (e.g. shadow root type, delegates focus, etc.) do not match, an exception is thrown. This, also, is a breaking change, but again hopefully not one that has compat implications.

Hopefully folks are happy with these changes. If so, I'll try shipping them in the next Chrome and verify the compat safety.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 18, 2024
Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

See [2] and [3] for the corresponding spec PRs.

[1] whatwg/dom#1235
[2] whatwg/html#10069
[3] whatwg/dom#1246

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 19, 2024
Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

See [2] and [3] for the corresponding spec PRs.

[1] whatwg/dom#1235
[2] whatwg/html#10069
[3] whatwg/dom#1246

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
aarongable pushed a commit to chromium/chromium that referenced this issue Jan 19, 2024
Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

See [2] and [3] for the corresponding spec PRs.

[1] whatwg/dom#1235
[2] whatwg/html#10069
[3] whatwg/dom#1246

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5191750
Commit-Queue: Mason Freed <[email protected]>
Auto-Submit: Mason Freed <[email protected]>
Commit-Queue: David Baron <[email protected]>
Reviewed-by: David Baron <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1249214}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 19, 2024
Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

See [2] and [3] for the corresponding spec PRs.

[1] whatwg/dom#1235
[2] whatwg/html#10069
[3] whatwg/dom#1246

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5191750
Commit-Queue: Mason Freed <[email protected]>
Auto-Submit: Mason Freed <[email protected]>
Commit-Queue: David Baron <[email protected]>
Reviewed-by: David Baron <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1249214}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 19, 2024
Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

See [2] and [3] for the corresponding spec PRs.

[1] whatwg/dom#1235
[2] whatwg/html#10069
[3] whatwg/dom#1246

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5191750
Commit-Queue: Mason Freed <[email protected]>
Auto-Submit: Mason Freed <[email protected]>
Commit-Queue: David Baron <[email protected]>
Reviewed-by: David Baron <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1249214}
@annevk
Copy link
Member

annevk commented Jan 19, 2024

Thanks @mfreed7, that works for us. I'll attempt to look at the PRs next week to double check all the details.

@mfreed7
Copy link
Contributor

mfreed7 commented Jan 19, 2024

Thanks @mfreed7, that works for us. I'll attempt to look at the PRs next week to double check all the details.

Great, thanks! I enabled the new behavior (and landed the WPTs) in Chrome 122, so I'll watch for issues.

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Jan 22, 2024
…mismatched imperative ones, a=testonly

Automatic update from web-platform-tests
Disallow multiple declarative roots and mismatched imperative ones

Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

See [2] and [3] for the corresponding spec PRs.

[1] whatwg/dom#1235
[2] whatwg/html#10069
[3] whatwg/dom#1246

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5191750
Commit-Queue: Mason Freed <[email protected]>
Auto-Submit: Mason Freed <[email protected]>
Commit-Queue: David Baron <[email protected]>
Reviewed-by: David Baron <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1249214}

--

wpt-commits: f18d8f8009c9256d24aad9439e00324d8eaff385
wpt-pr: 43958
ErichDonGubler pushed a commit to erichdongubler-mozilla/firefox that referenced this issue Jan 23, 2024
…mismatched imperative ones, a=testonly

Automatic update from web-platform-tests
Disallow multiple declarative roots and mismatched imperative ones

Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

See [2] and [3] for the corresponding spec PRs.

[1] whatwg/dom#1235
[2] whatwg/html#10069
[3] whatwg/dom#1246

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5191750
Commit-Queue: Mason Freed <[email protected]>
Auto-Submit: Mason Freed <[email protected]>
Commit-Queue: David Baron <[email protected]>
Reviewed-by: David Baron <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1249214}

--

wpt-commits: f18d8f8009c9256d24aad9439e00324d8eaff385
wpt-pr: 43958
mfreed7 added a commit to mfreed7/html that referenced this issue Jan 27, 2024
Per the discussion at whatwg/dom#1235, this PR makes the *first* declarative shadow root "win". Prior behavior was for the *last* one to remain, but this PR changes second and subsequent declarative shadow roots to report an exception instead.
mfreed7 added a commit to mfreed7/dom that referenced this issue Jan 27, 2024
Per the discussion at whatwg#1235, this PR changes the behavior when calling `attachShadow()` on a node with an existing declarative shadow root. Now, if the parameters do not match between the arguments to `attachShadow()` and the existing root, throw an exception. Prior behavior was to silently return the declarative root as-is, with mismatched parameters.
annevk pushed a commit to mfreed7/html that referenced this issue Feb 13, 2024
Per the discussion at whatwg/dom#1235, this PR makes the *first* declarative shadow root "win". Prior behavior was for the *last* one to remain, but this PR changes second and subsequent declarative shadow roots to report an exception instead.
annevk pushed a commit to whatwg/html that referenced this issue Feb 15, 2024
Per the discussion at whatwg/dom#1235, this PR makes the *first* declarative shadow root "win". Prior behavior was for the *last* one to remain, but this PR changes second and subsequent declarative shadow roots to report an exception instead.
@annevk annevk added the topic: shadow Relates to shadow trees (as defined in DOM) label Feb 16, 2024
annevk added a commit that referenced this issue Feb 16, 2024
This changes the behavior when calling `attachShadow()` on a node with an existing declarative shadow root. Now, if mode does not match between the arguments to `attachShadow()` and the existing root, throw an exception. Prior behavior was to silently return the declarative root as-is, with mismatched parameters.

Additionally, remove the note as it was incorrect.

See also: whatwg/html#10069.

Fixes #1235.

Co-authored-by: Anne van Kesteren <[email protected]>
marcoscaceres pushed a commit to web-platform-tests/wpt that referenced this issue Feb 23, 2024
Two changes:
 1. If two declarative shadow roots are included within a single
    host element, only the *first* one will remain. This is a
    change in behavior from before, but reached consensus [1]
    and hopefully won't be a breaking change for anyone.
 2. If attachShadow() is used on an existing declarative shadow
    root, and the parameters (e.g. shadow root type, etc.) do
    not match, an exception is thrown. This, also, is a breaking
    change, but hopefully not one that gets hit. See also [1].

See [2] and [3] for the corresponding spec PRs.

[1] whatwg/dom#1235
[2] whatwg/html#10069
[3] whatwg/dom#1246

Bug: 1379513,1042130
Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5191750
Commit-Queue: Mason Freed <[email protected]>
Auto-Submit: Mason Freed <[email protected]>
Commit-Queue: David Baron <[email protected]>
Reviewed-by: David Baron <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1249214}
vinhill pushed a commit to vinhill/dom that referenced this issue Jun 20, 2024
This changes the behavior when calling `attachShadow()` on a node with an existing declarative shadow root. Now, if mode does not match between the arguments to `attachShadow()` and the existing root, throw an exception. Prior behavior was to silently return the declarative root as-is, with mismatched parameters.

Additionally, remove the note as it was incorrect.

See also: whatwg/html#10069.

Fixes whatwg#1235.

Co-authored-by: Anne van Kesteren <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: shadow Relates to shadow trees (as defined in DOM)
Development

Successfully merging a pull request may close this issue.

4 participants