Overriding HTMLElement.attachShadow breaks other polyfills
See original GitHub issueDescribe the bug
attachShadow
is defined (per spec) on Element
but this polyfill sets it on HTMLElement.prototype
If anyone else later changes Element.prototype.attachShadow
, their code is never called (on HTMLElements), because this library’s polyfill takes precedence, and revert to the native attachShadow code (captured during init).
To Reproduce https://codesandbox.io/s/attachshadow-bug-demo-w33wp Loading it on Chrome shows “Should be called” on console (this library doesn’t patch attachShadow). Loading it on Firefox doesn’t. Switching the order of polyfills fixes the issue for Firefox (need to reload the sandbox for the prototypes to be reset)
Expected behavior attachShadow being defined on Element as per the spec, that’s where it should be defined to play fine with other polyfills/hooks.
Additional context Polyfill confirmed to break if applied after this one: @lwc/synthetic-shadow
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
This is fixed in version 2.4.2. Thanks for bringing this to my attention.
Exactly, but it does so only for lwc components, for other elements it reverts to native attachShadow, so this polyfill would still work for those.