-
Notifications
You must be signed in to change notification settings - Fork 294
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
Comments
(Forgot the ccs, hah) |
I did think about this one. The important detail (to me at least) is that I do agree that it's perhaps a bit odd that the options provided to |
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 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? |
Why did we not throw again? I'm also not sure I understand
upon rereading. How could a host ever have multiple shadow roots? |
You'd have multiple |
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. |
That's true. But typically this (DSD) is already "action at a distance" by definition, since it's rendered on the server.
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?
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 Importantly, if the server is taking a component that calls
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 " |
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 |
For the wording issue: yes,
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. |
Yes, otherwise they get silently ignored... |
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 |
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 What does the parser do when a script attached a shadow root? |
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. |
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
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
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
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
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
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
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.
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.
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
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
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
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:
Hopefully folks are happy with these changes. If so, I'll try shipping them in the next Chrome and verify the compat safety. |
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
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
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}
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}
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}
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. |
…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
…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
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.
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.
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.
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.
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]>
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}
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]>
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 theShadowRootInit
members don't match the declarative shadow DOM attributes...Is that intentional? If it is it might at least be worth a note.
The text was updated successfully, but these errors were encountered: