-
Notifications
You must be signed in to change notification settings - Fork 373
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
Expose shadowRoot on element internals #871
Comments
We (Apple's WebKit team) initially suggested two alternatives to this approach:
We'll review this alternative approach (exposing shadow root on |
that seems a lot more complicated, |
That's not at all what I'm suggesting. I'm suggesting that attachShadow would return the existing declarative shadow root instead of creating a new one. |
@rniwa During Mason's presentation, we mentioned that the problem with this approach is that it is not backward compatible, components that are not taking declarative shadow root into consideration, will fail because they will assume an empty shadowRoot was created. |
@caridy I don't see how that will ever happen. A component will necessarily have to cooperate to produce a declarative version of its shadow root. How else would it get a valid one? |
@justinfagnani as we discussed in the meeting, we believe that it should be backward compatible, letting existing components and simple components to function even when used through SSR via declarative shadow root. Yes, the component will wipe out the existing shadow if the component doesn't take it into consideration, that's fine. @mfreed7 agreed with that IIRC. We should probably have this issue in the declarative shadow root proposal repo, I don't think that decision affects this request for element internals to expose the shadow root. |
@caridy can you outline how a component would even get a valid shadow root generated for it without cooperation from the element or framework it's built in? It affects this feature request because creating a new shadow root is a very new behavior. |
Thanks @JanMiksovsky for opening this issue. It seems that there are two relevant potential use cases here:
It would seem that the most clean API to address both cases above would be:
@justinfagnani, I could imagine a framework that simply renders all content server-side, and then calls |
It seems awkward that all SSR aware components would have to write code like this: class CustomHTMLElement extends HTMLElement {
#internals;
constructor() {
super();
#internals = this.attachInternals();
if (!#internals.shadowRoot)
this.attachShadow({mode: 'closed'});
}
} With the alternative I'm proposing (make attachShadow return the exiting declarative shadowRoot), we could something like this (obviously with a shorter name): class CustomHTMLElement extends HTMLElement {
#shadowRoot;
constructor() {
super();
#shadowRoot = this.attachShadow({mode: 'closed', returnExistingDeclarativeShadowRoot: true});
}
} We could do both too. |
Many templating libraries that support hydration will still need to branch on some factor to either call the initial rendering or hydrating entrypoint. The existence of a shadow root is a pretty decent signal for this, IMO. |
@rniwa , just to double-check your proposal: #shadowRoot = this.attachShadow({mode: 'closed', returnExistingDeclarativeShadowRoot: true}); will return the existing declarative shadow root, with contents included. #shadowRoot = this.attachShadow({mode: 'closed'}); will instead blow away the existing contents of the shadow root and return an empty root. In both cases, no exception will be thrown if a declarative shadow root already exists. However, if there is already an imperatively-created shadow root, these will both throw, as they do today. Is that right? If so, I think I'm ok with that proposal also. |
Right.
Now I realize the situation is a lot more complicated than that because of the sync parsing behavior in which case the custom element gets created before any of its children get parsed. In that scenario (non-upgrading case), you'd have to wait until all the children had been parsed for hydration. |
With the current declarative SR proposal, this is fine, as the entire shadow root is created when all the shadow children are parsed. If we found an acceptable way to do streaming, this would be an issue to tackle too. Edit: I suppose the constructor could be called before the declarative shadow root is created at all. This would be a great time to add the |
No, it's not fine because the constructor of a custom element is always called before its children are parsed or created so in sync/non-upgrade construction case, the constructor will always run and then it can attach a non-declarative shadow root.
This is not could. It's guaranteed to happen in that order.
That doesn't necessarily solve the problem fully because then the custom element has to delay attaching a shadow root until that happens in the case there is a declarative shadow root, in which case, someone else can attach a shadow root, or worse yet, anyone can access to template's content and have reference to those nodes. |
Declarative shadow roots are necessarily a cooperative construct - the generator of the shadow root and the element have to coordinate - and I'm definitely not worried about breaking encapsulation this way. A component will have to opt-in to SSR somehow and have to trust the declarative SR contents. If a component author is worried that there will somehow be an attack via declarative SR, then they should not support it, ie, it should throw when they call This is why I don't see a forgiving version of |
Breaking encapsulation in this scenario would definitely be a show stopper for us.
This is not about the malicious case of something attacking since there is no security boundary right now. However, it's very easy for some residual script on a page to start accessing random nodes via MutationObserver, etc... |
I've just posted a larger comment on the 831 issue, which should be read before this one for context. But I wanted to point out one problem with the |
I would like to re-iterate my comment, and propose that we solve this issue by adding the following to the ElementInternals interface: interface ElementInternals {
readonly attribute ShadowRoot? shadowRoot;
}; internals.shadowRoot: Returns internals's target element's shadow root. This attribute will return both open and closed shadow roots. If shadow is null, then return null. If there is general agreement on this, then I will put together a spec PR, and will get this implemented in Chromium. |
See [1] for context. This CL adds the shadowRoot attribute to ElementInternals, which allows custom elements to access their own shadow roots, including in the case that the shadowRoot is closed. Without this capability, custom elements that use closed declarative shadow roots would have no ability to retrieve the contents of their own shadow root. Bug: 1042130 [1] WICG/webcomponents#871 (comment) Change-Id: I33606144bec3c27600d2e67f108d0344f7696dd2
See [1] for context. This CL adds the shadowRoot attribute to ElementInternals, which allows custom elements to access their own shadow roots, including in the case that the shadowRoot is closed. Without this capability, custom elements that use closed declarative shadow roots would have no ability to retrieve the contents of their own shadow root. Bug: 1042130 [1] WICG/webcomponents#871 (comment) Change-Id: I33606144bec3c27600d2e67f108d0344f7696dd2
See [1] for context. This CL adds the shadowRoot attribute to ElementInternals, which allows custom elements to access their own shadow roots, including in the case that the shadowRoot is closed. Without this capability, custom elements that use closed declarative shadow roots would have no ability to retrieve the contents of their own shadow root. Bug: 1042130 [1] WICG/webcomponents#871 (comment) Change-Id: I33606144bec3c27600d2e67f108d0344f7696dd2
See [1] for context. This CL adds the shadowRoot attribute to ElementInternals, which allows custom elements to access their own shadow roots, including in the case that the shadowRoot is closed. Without this capability, custom elements that use closed declarative shadow roots would have no ability to retrieve the contents of their own shadow root. Bug: 1042130 [1] WICG/webcomponents#871 (comment) Change-Id: I33606144bec3c27600d2e67f108d0344f7696dd2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2350739 Commit-Queue: Mason Freed <masonfreed@chromium.org> Auto-Submit: Mason Freed <masonfreed@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Cr-Commit-Position: refs/heads/master@{#797729}
To allow testing, I've implemented this in Chromium behind the DeclarativeShadowDOM flag, with WPT tests. Very straightforward implementation, and I believe it solves the issues brought up here. But comments appreciated. |
Per the discussion at [1], the intention of this change is to prevent calls to attachInternals() prior to the constructor of the custom element having a chance to do so. The spec PR is at [2]. This change is gated behind the DeclarativeShadowDOM flag. With the flag disabled (the default), a use counter is added for checking on the web compatibility of this change. The use counter will measure the cases where attachInternals() is being called in a to-be-outlawed way. [1] WICG/webcomponents#871 (comment) [2] whatwg/html#5909 Bug: 1042130 Change-Id: Iacf97a49133b5f7f44710e5c0287f01cfebe4c44 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392975 Reviewed-by: Alexei Svitkine <asvitkine@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Commit-Queue: Mason Freed <masonfreed@chromium.org> Auto-Submit: Mason Freed <masonfreed@chromium.org> Cr-Commit-Position: refs/heads/master@{#806830}
Per the spec issue [1], this change disallows the use of ElementInternals.shadowRoot for shadow roots created prior to the custom element constructor being run. This protects potentially-closed shadow roots, created outside of the custom element, from being revealed to the custom element itself. (Use case unclear, but this was the request.) [1] WICG/webcomponents#871 Bug: 1042130 Change-Id: I25192256e8b1334d09ea587f29d64f35d4f5f949
Great. I've added two more spec PRs for this change, one in HTML and one in DOM. This makes four open PRs here, which could use reviews:
Ok, thanks for the update. I would really appreciate your thoughts soon - we are proceeding with an Origin Trial as we speak, and I'd love to ship this feature soon. I would prefer not to do that without your input and support. As I mentioned in the main thread, I believe the currently-proposed solution is worthwhile, for reasons other than pure performance. |
Per the spec issue [1], this change disallows the use of ElementInternals.shadowRoot for shadow roots created prior to the custom element constructor being run. This protects potentially-closed shadow roots, created outside of the custom element, from being revealed to the custom element itself. (Use case unclear, but this was the request.) [1] WICG/webcomponents#871 Bug: 1042130 Change-Id: I25192256e8b1334d09ea587f29d64f35d4f5f949 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412470 Commit-Queue: Kouhei Ueno <kouhei@chromium.org> Auto-Submit: Mason Freed <masonfreed@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Cr-Commit-Position: refs/heads/master@{#807311}
Per the spec issue [1], this change disallows the use of ElementInternals.shadowRoot for shadow roots created prior to the custom element constructor being run. This protects potentially-closed shadow roots, created outside of the custom element, from being revealed to the custom element itself. (Use case unclear, but this was the request.) [1] WICG/webcomponents#871 Bug: 1042130 Change-Id: I25192256e8b1334d09ea587f29d64f35d4f5f949 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412470 Commit-Queue: Kouhei Ueno <kouhei@chromium.org> Auto-Submit: Mason Freed <masonfreed@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Cr-Commit-Position: refs/heads/master@{#807311}
Per the spec issue [1], this change disallows the use of ElementInternals.shadowRoot for shadow roots created prior to the custom element constructor being run. This protects potentially-closed shadow roots, created outside of the custom element, from being revealed to the custom element itself. (Use case unclear, but this was the request.) [1] WICG/webcomponents#871 Bug: 1042130 Change-Id: I25192256e8b1334d09ea587f29d64f35d4f5f949 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412470 Commit-Queue: Kouhei Ueno <kouhei@chromium.org> Auto-Submit: Mason Freed <masonfreed@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Cr-Commit-Position: refs/heads/master@{#807311}
…ide or after the constructor, a=testonly Automatic update from web-platform-tests Restrict attachInternals() to be run inside or after the constructor Per the discussion at [1], the intention of this change is to prevent calls to attachInternals() prior to the constructor of the custom element having a chance to do so. The spec PR is at [2]. This change is gated behind the DeclarativeShadowDOM flag. With the flag disabled (the default), a use counter is added for checking on the web compatibility of this change. The use counter will measure the cases where attachInternals() is being called in a to-be-outlawed way. [1] WICG/webcomponents#871 (comment) [2] whatwg/html#5909 Bug: 1042130 Change-Id: Iacf97a49133b5f7f44710e5c0287f01cfebe4c44 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392975 Reviewed-by: Alexei Svitkine <asvitkine@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Commit-Queue: Mason Freed <masonfreed@chromium.org> Auto-Submit: Mason Freed <masonfreed@chromium.org> Cr-Commit-Position: refs/heads/master@{#806830} -- wpt-commits: df5b354d012f3bb0db1524bfaf8a4e16b4b01cc2 wpt-pr: 25402
…-created shadow roots, a=testonly Automatic update from web-platform-tests Deny ElementInternals.shadowRoot for pre-created shadow roots Per the spec issue [1], this change disallows the use of ElementInternals.shadowRoot for shadow roots created prior to the custom element constructor being run. This protects potentially-closed shadow roots, created outside of the custom element, from being revealed to the custom element itself. (Use case unclear, but this was the request.) [1] WICG/webcomponents#871 Bug: 1042130 Change-Id: I25192256e8b1334d09ea587f29d64f35d4f5f949 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412470 Commit-Queue: Kouhei Ueno <kouhei@chromium.org> Auto-Submit: Mason Freed <masonfreed@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Cr-Commit-Position: refs/heads/master@{#807311} -- wpt-commits: 8e3392df536283e843589c176ffbc7e00e94e64e wpt-pr: 25554
…ide or after the constructor, a=testonly Automatic update from web-platform-tests Restrict attachInternals() to be run inside or after the constructor Per the discussion at [1], the intention of this change is to prevent calls to attachInternals() prior to the constructor of the custom element having a chance to do so. The spec PR is at [2]. This change is gated behind the DeclarativeShadowDOM flag. With the flag disabled (the default), a use counter is added for checking on the web compatibility of this change. The use counter will measure the cases where attachInternals() is being called in a to-be-outlawed way. [1] WICG/webcomponents#871 (comment) [2] whatwg/html#5909 Bug: 1042130 Change-Id: Iacf97a49133b5f7f44710e5c0287f01cfebe4c44 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392975 Reviewed-by: Alexei Svitkine <asvitkine@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Commit-Queue: Mason Freed <masonfreed@chromium.org> Auto-Submit: Mason Freed <masonfreed@chromium.org> Cr-Commit-Position: refs/heads/master@{#806830} -- wpt-commits: df5b354d012f3bb0db1524bfaf8a4e16b4b01cc2 wpt-pr: 25402
…-created shadow roots, a=testonly Automatic update from web-platform-tests Deny ElementInternals.shadowRoot for pre-created shadow roots Per the spec issue [1], this change disallows the use of ElementInternals.shadowRoot for shadow roots created prior to the custom element constructor being run. This protects potentially-closed shadow roots, created outside of the custom element, from being revealed to the custom element itself. (Use case unclear, but this was the request.) [1] WICG/webcomponents#871 Bug: 1042130 Change-Id: I25192256e8b1334d09ea587f29d64f35d4f5f949 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412470 Commit-Queue: Kouhei Ueno <kouhei@chromium.org> Auto-Submit: Mason Freed <masonfreed@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Cr-Commit-Position: refs/heads/master@{#807311} -- wpt-commits: 8e3392df536283e843589c176ffbc7e00e94e64e wpt-pr: 25554
…ide or after the constructor, a=testonly Automatic update from web-platform-tests Restrict attachInternals() to be run inside or after the constructor Per the discussion at [1], the intention of this change is to prevent calls to attachInternals() prior to the constructor of the custom element having a chance to do so. The spec PR is at [2]. This change is gated behind the DeclarativeShadowDOM flag. With the flag disabled (the default), a use counter is added for checking on the web compatibility of this change. The use counter will measure the cases where attachInternals() is being called in a to-be-outlawed way. [1] WICG/webcomponents#871 (comment) [2] whatwg/html#5909 Bug: 1042130 Change-Id: Iacf97a49133b5f7f44710e5c0287f01cfebe4c44 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392975 Reviewed-by: Alexei Svitkine <asvitkinechromium.org> Reviewed-by: Kouhei Ueno <kouheichromium.org> Commit-Queue: Mason Freed <masonfreedchromium.org> Auto-Submit: Mason Freed <masonfreedchromium.org> Cr-Commit-Position: refs/heads/master{#806830} -- wpt-commits: df5b354d012f3bb0db1524bfaf8a4e16b4b01cc2 wpt-pr: 25402 UltraBlame original commit: 56afece076c057fd659c3c180e1673c5a409a614
…-created shadow roots, a=testonly Automatic update from web-platform-tests Deny ElementInternals.shadowRoot for pre-created shadow roots Per the spec issue [1], this change disallows the use of ElementInternals.shadowRoot for shadow roots created prior to the custom element constructor being run. This protects potentially-closed shadow roots, created outside of the custom element, from being revealed to the custom element itself. (Use case unclear, but this was the request.) [1] WICG/webcomponents#871 Bug: 1042130 Change-Id: I25192256e8b1334d09ea587f29d64f35d4f5f949 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412470 Commit-Queue: Kouhei Ueno <kouheichromium.org> Auto-Submit: Mason Freed <masonfreedchromium.org> Reviewed-by: Kouhei Ueno <kouheichromium.org> Cr-Commit-Position: refs/heads/master{#807311} -- wpt-commits: 8e3392df536283e843589c176ffbc7e00e94e64e wpt-pr: 25554 UltraBlame original commit: 11691695d1b65041eea7dd2470183b95f4335029
…ide or after the constructor, a=testonly Automatic update from web-platform-tests Restrict attachInternals() to be run inside or after the constructor Per the discussion at [1], the intention of this change is to prevent calls to attachInternals() prior to the constructor of the custom element having a chance to do so. The spec PR is at [2]. This change is gated behind the DeclarativeShadowDOM flag. With the flag disabled (the default), a use counter is added for checking on the web compatibility of this change. The use counter will measure the cases where attachInternals() is being called in a to-be-outlawed way. [1] WICG/webcomponents#871 (comment) [2] whatwg/html#5909 Bug: 1042130 Change-Id: Iacf97a49133b5f7f44710e5c0287f01cfebe4c44 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392975 Reviewed-by: Alexei Svitkine <asvitkinechromium.org> Reviewed-by: Kouhei Ueno <kouheichromium.org> Commit-Queue: Mason Freed <masonfreedchromium.org> Auto-Submit: Mason Freed <masonfreedchromium.org> Cr-Commit-Position: refs/heads/master{#806830} -- wpt-commits: df5b354d012f3bb0db1524bfaf8a4e16b4b01cc2 wpt-pr: 25402 UltraBlame original commit: 56afece076c057fd659c3c180e1673c5a409a614
…-created shadow roots, a=testonly Automatic update from web-platform-tests Deny ElementInternals.shadowRoot for pre-created shadow roots Per the spec issue [1], this change disallows the use of ElementInternals.shadowRoot for shadow roots created prior to the custom element constructor being run. This protects potentially-closed shadow roots, created outside of the custom element, from being revealed to the custom element itself. (Use case unclear, but this was the request.) [1] WICG/webcomponents#871 Bug: 1042130 Change-Id: I25192256e8b1334d09ea587f29d64f35d4f5f949 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412470 Commit-Queue: Kouhei Ueno <kouheichromium.org> Auto-Submit: Mason Freed <masonfreedchromium.org> Reviewed-by: Kouhei Ueno <kouheichromium.org> Cr-Commit-Position: refs/heads/master{#807311} -- wpt-commits: 8e3392df536283e843589c176ffbc7e00e94e64e wpt-pr: 25554 UltraBlame original commit: 11691695d1b65041eea7dd2470183b95f4335029
…ide or after the constructor, a=testonly Automatic update from web-platform-tests Restrict attachInternals() to be run inside or after the constructor Per the discussion at [1], the intention of this change is to prevent calls to attachInternals() prior to the constructor of the custom element having a chance to do so. The spec PR is at [2]. This change is gated behind the DeclarativeShadowDOM flag. With the flag disabled (the default), a use counter is added for checking on the web compatibility of this change. The use counter will measure the cases where attachInternals() is being called in a to-be-outlawed way. [1] WICG/webcomponents#871 (comment) [2] whatwg/html#5909 Bug: 1042130 Change-Id: Iacf97a49133b5f7f44710e5c0287f01cfebe4c44 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392975 Reviewed-by: Alexei Svitkine <asvitkinechromium.org> Reviewed-by: Kouhei Ueno <kouheichromium.org> Commit-Queue: Mason Freed <masonfreedchromium.org> Auto-Submit: Mason Freed <masonfreedchromium.org> Cr-Commit-Position: refs/heads/master{#806830} -- wpt-commits: df5b354d012f3bb0db1524bfaf8a4e16b4b01cc2 wpt-pr: 25402 UltraBlame original commit: 56afece076c057fd659c3c180e1673c5a409a614
…-created shadow roots, a=testonly Automatic update from web-platform-tests Deny ElementInternals.shadowRoot for pre-created shadow roots Per the spec issue [1], this change disallows the use of ElementInternals.shadowRoot for shadow roots created prior to the custom element constructor being run. This protects potentially-closed shadow roots, created outside of the custom element, from being revealed to the custom element itself. (Use case unclear, but this was the request.) [1] WICG/webcomponents#871 Bug: 1042130 Change-Id: I25192256e8b1334d09ea587f29d64f35d4f5f949 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412470 Commit-Queue: Kouhei Ueno <kouheichromium.org> Auto-Submit: Mason Freed <masonfreedchromium.org> Reviewed-by: Kouhei Ueno <kouheichromium.org> Cr-Commit-Position: refs/heads/master{#807311} -- wpt-commits: 8e3392df536283e843589c176ffbc7e00e94e64e wpt-pr: 25554 UltraBlame original commit: 11691695d1b65041eea7dd2470183b95f4335029
This is for use with whatwg/html#5912, which restricts access to ElementInternals's shadowRoot property for shadow roots which were pre-existing before a custom element upgrade/construction. See the discussion in WICG/webcomponents#871 (comment) for more context.
Thanks for the PR reviews here, I'm glad we could put together a solution to this problem. While this is closed, I will continue to monitor the use counters I recently added for usage of the |
…turns both open and closed roots, a=testonly Automatic update from web-platform-tests Add ElementInternals.shadowRoot which returns both open and closed roots See [1] for context. This CL adds the shadowRoot attribute to ElementInternals, which allows custom elements to access their own shadow roots, including in the case that the shadowRoot is closed. Without this capability, custom elements that use closed declarative shadow roots would have no ability to retrieve the contents of their own shadow root. Bug: 1042130 [1] WICG/webcomponents#871 (comment) Change-Id: I33606144bec3c27600d2e67f108d0344f7696dd2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2350739 Commit-Queue: Mason Freed <masonfreed@chromium.org> Auto-Submit: Mason Freed <masonfreed@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Cr-Commit-Position: refs/heads/master@{#797729} -- wpt-commits: 9734707a86c1a14cba63bb80d8c391dd7dea004f wpt-pr: 24969
See [1] for context. This CL adds the shadowRoot attribute to ElementInternals, which allows custom elements to access their own shadow roots, including in the case that the shadowRoot is closed. Without this capability, custom elements that use closed declarative shadow roots would have no ability to retrieve the contents of their own shadow root. Bug: 1042130 [1] WICG/webcomponents#871 (comment) Change-Id: I33606144bec3c27600d2e67f108d0344f7696dd2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2350739 Commit-Queue: Mason Freed <masonfreed@chromium.org> Auto-Submit: Mason Freed <masonfreed@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#797729} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 9e291a961dbb34688f539a0ad10bd3cb3874a61a
Per the discussion at [1], the intention of this change is to prevent calls to attachInternals() prior to the constructor of the custom element having a chance to do so. The spec PR is at [2]. This change is gated behind the DeclarativeShadowDOM flag. With the flag disabled (the default), a use counter is added for checking on the web compatibility of this change. The use counter will measure the cases where attachInternals() is being called in a to-be-outlawed way. [1] WICG/webcomponents#871 (comment) [2] whatwg/html#5909 Bug: 1042130 Change-Id: Iacf97a49133b5f7f44710e5c0287f01cfebe4c44 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392975 Reviewed-by: Alexei Svitkine <asvitkine@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Commit-Queue: Mason Freed <masonfreed@chromium.org> Auto-Submit: Mason Freed <masonfreed@chromium.org> Cr-Commit-Position: refs/heads/master@{#806830} GitOrigin-RevId: 8f4d32caa68b363efdb4cd27821f3d893ff6f464
Per the spec issue [1], this change disallows the use of ElementInternals.shadowRoot for shadow roots created prior to the custom element constructor being run. This protects potentially-closed shadow roots, created outside of the custom element, from being revealed to the custom element itself. (Use case unclear, but this was the request.) [1] WICG/webcomponents#871 Bug: 1042130 Change-Id: I25192256e8b1334d09ea587f29d64f35d4f5f949 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412470 Commit-Queue: Kouhei Ueno <kouhei@chromium.org> Auto-Submit: Mason Freed <masonfreed@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Cr-Commit-Position: refs/heads/master@{#807311} GitOrigin-RevId: 2372aae3a33f3928c0964defb4f01b9be77ef3ce
During the March 2020 web components virtual F2F, we discussed the fact that an element with a closed shadow root has no standard way to refer to its own shadow root:
Because of this, any component that creates a closed root must maintain its own private reference to the root.
Additionally, the possibility of declarative Shadow DOM introduces a scenario in which a rehydrated component may need access to a shadow root that was automatically created for it.
For these reasons, it seems worthwhile to expose
shadowRoot
on an element's internals:As before, the component must still maintain a private reference (to internals instead of the shadow root), but at least now:
shadowRoot
.attachInternals
and then inspect the internals to determine whether a shadow root has already been created.The text was updated successfully, but these errors were encountered: