-
Notifications
You must be signed in to change notification settings - Fork 305
[ElementInternals] ElementInternals.shadowRoot
is null
but this.shadowRoot
is not (its a ShadowRoot
)
#1365
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
Comments
ElementInternals.shadowRoot
is null
but this.shadowRoot
is not (its a ShadowRoot
)ElementInternals.shadowRoot
is null
but this.shadowRoot
is not (its a ShadowRoot
)
ElementInternals.shadowRoot
is null
but this.shadowRoot
is not (its a ShadowRoot
)ElementInternals.shadowRoot
is null
but this.shadowRoot
is not (its a ShadowRoot
)
The solution seems to be that the upgrade process should set the root's |
Why is a ShadowRoot It is not possible to get <script type=module>
customElements.define( 'x-x', class extends HTMLElement { } )
const t = document.createElement('template')
t.innerHTML = `<x-x></x-x>`
const el = t.content.children[0]
el.attachShadow({mode: 'open'})
const internals = el.attachInternals()
console.log(internals.shadowRoot, el.shadowRoot)
</script> Based on the that, the only place that a custom element author can ever start to use Unless I missed something, it seems that
Are |
I recommend looking at blame as to why it was introduced. |
It was introduced to prevent someone defining an non-defined custom element (element with dash in the name) later, and getting access to a closed Why: 1) This issue causes another problem that is not so obvious: Custom Elements defined with synchronous script tags before parsing cannot use DSD, because this issue breaks CE code (constructors will see In order to use DSD, custom element definitions have to happen after parsing. This is a huge problem. I know people who have already sworn that defining elements up front is the best way to go for various reasons (name: avoid upgrade ordering issues, avoid flash of unstyled content). And now, with this 2) DSD requires custom elements being able to accept declarative ShadowRoots, for server side rendering. ShadowDOM is not a security feature, right? Right? If not, then there's no strong need to have the odd behavior. I believe ElementInternals needs to be in sync with the state of the element's ShadowRoot existence for the sake of developer sanity. We're starting to more deeply explore the era of SSR for Custom Elements, and I don't want people who haven't tried SSR yet to hit a road block due to this. People have already had enough trauma from element upgrade ordering. Strong vote to remove this limitation. |
There's one more issue that needs to be addressed for DSD to be useful for everyone: both the element tag name, and the template, should be parsed together: Example 1: <my-el>
<p>
<!-- parser will now instantiate <my-el> because it knows there is no `<template shadowrootmode>` at the top --> Example 2: <my-el>
<template shadowrootmode="open">
<!-- parser will now instantiate <my-el> because it knows it has a `<template shadowrootmode>` at the top --> I know that someone will say "this ship has sailed". Can we turn it around? So that we can simplify developer lives for CEs + DSD? My hope and wish is for web specs to move forward without making things so complicated for CE users (vanilla web platform users). |
@sorvell mentioned that to maintain BC, I think we will likely need something like: parsingCompleteCallback() {
if (!this.#internals.shadowRoot) {
this.attachShadow(...);
}
} but this means it requires JavaScript. We are also thinking about a Declarative Custom Elements solution. We don't want those people to be required to use JavaScript for DSD. |
You are combining too many things in a single issue. It's no longer clear to me what this issue is about. I'm quite certain however we don't want to revisit the design OP discusses. |
(content deleted, need to think about this more to provide a concise explainer with solution ideas) |
What is the issue with the DOM Standard?
I've found a situation in which an element's
ElementInternals.shadowRoot
property is not in sync with the actual state of the DOM, i.e. when anopen
ShadowRoot
is added to an element,element.shadowRoot !== elementInternals.shadowRoot
.This is reproducible in all browsers:
https://codepen.io/trusktr/pen/NPWmGMV
full code:
This code,
should either log two
null
values at any point in time, or twoShadowRoot
values at any point in time when the root mode isopen
, for consistency.When the root mode is
closed
(if you update the example), the output should beShadowRoot
null
instead ofnull
ShadowRoot
, but the output is actuallynull
null
.Either way, an error like the following will be show in console despite what the state says:
The text was updated successfully, but these errors were encountered: