Skip to content
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

[scoped-custom-element-registry] Elements can lose registry when removed from DOM #569

Open
sorvell opened this issue Dec 5, 2023 · 1 comment

Comments

@sorvell
Copy link
Collaborator

sorvell commented Dec 5, 2023

Description

If a nested element is removed from a shadowRoot using a registry and then innerHTML is called on it with html containing a scoped element, the element will not customize.

Example

Playground example

Expected behavior

Both elements in the example should customize.

Actual behavior

The 2nd scoped element fails to customize.

@sorvell
Copy link
Collaborator Author

sorvell commented Dec 5, 2023

Here are 3 possible ways to fix this issue:

  1. When trees of elements are created inside scoped roots (via innerHTML, insertAdjacentHtml, importNode, and maybe cloneNode?), stamp the entire subtree of elements with the creating registry. Currently only the top-most element is stamped.

    Preferred This will be a small perf hit but is robust and simple.

  2. Patch all DOM modification APIs to "pass along" the registry before mutating the DOM. This would involve patching a lot of the API surface area, e.g. all append's, all replaceWith..., all remove/removeChild, all setters textContent, innerHTML, innerText, outerText.

    Issues There's a lot to maintain and get right here and a large amount of code to add.

  3. Use a MutationObserver to detect DOM changes. This seems straightforward, but it would need to observe disconnected nodes as well, and likely would want to un-observe them when re-connection.

    Issues This is also a lot to get just right, validate, and maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant