A new attribute on ElementInternals, 'shadowRoot', allows custom elements to access their own ShadowRoot, regardless of open/closed status. Additionally, further restrictions are added to the attachInternals() API to ensure that custom elements get the first chance to attach the ElementInternals interface. With this change, the attachInternals() function will throw an exception if called prior to the custom element constructor being run.
Interoperability and Compatibility
There is a very small potential compat issue, specifically with the change to attachInternals() not being allowed prior to the custom element constructor. However, use counters indicate almost no usage that would be broken by this change:
The overall usage of the attachInternals() API is quite low by itself, around 0.001%: https://chromestatus.com/metrics/feature/timeline/popularity/3435
The to-be-disallowed usage of attachInternals() *prior* to the constructor shows no measurable usage (0%): https://chromestatus.com/metrics/feature/timeline/popularity/3470
Based on these use counters, the risk here is quite low.
As for interoperability risk, there is multi-implementer support, and the spec has been approved and landed. So the interop risk should be low also.Gecko
: No signalWebKit
: Positive (https://github.com/w3c/webcomponents/issues/871#issuecomment-692383222
) The landed spec was reviewed and assisted by rniwa@ from WebKit.Web developers
: No signals
This feature will likely be used more often by components taking advantage of the declarative Shadow DOM feature. However, this feature is also useful on its own.
There should be no ergonomic risks to adding this API.
Polyfills could be developed for ElementInternals.shadowRoot, by patching attachShadow. It is unclear whether development of a polyfill will take place. It is likely not worth significant documentation or outreach for this feature.
The only real security concern that was taken into account was the change to attachInternals() to prevent access prior to the custom element constructor running. This change should protect closed shadow roots references from being accessed prior to custom element upgrades.
This is a JS only change/feature, and should be supported by the DevTools console.