Skip to content

Conversation

@namukang
Copy link

@namukang namukang commented Oct 15, 2025

@webext-core/isolated-element currently creates a full HTML document when setting up the shadow DOM. This is incorrect, as the shadow DOM is a fragment of the DOM tree, not a full HTML document.

Example on MDN of setting up a shadow DOM: https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM#creating_a_shadow_dom

Fixes #105

Companion PR for wxt: wxt-dev/wxt#1939

Add test to ensure the shadow DOM does not contain a full HTML
document structure (<html>, <head>, <body> elements) and instead
uses a simple <div> element as the isolated container.
Replace html/head/body structure with simpler div element
to avoid invalid DOM nesting
@namukang namukang changed the title fix: shadow dom should be a subtree, not a full HTML document fix: shadow dom should not be a full HTML document Oct 15, 2025
namukang added a commit to namukang/wxt that referenced this pull request Oct 15, 2025
@aklinker1
Copy link
Owner

aklinker1 commented Oct 25, 2025

This is done purposefully to support CSS libraries like tailwindcss that expect an HTML structure add styles inside :root { }. Without this, CSS variables defined there are not available.

Since most modern CSS frameworks require this, it's not something I plan on changing.

If this behavior doesn't work for you, you can implement your own isolated element helper. I'd be more than willing to point you in the correct direction!

I would be more open to a flag that toggles between the two modes, full HTML vs fragment, than not supporting the full HTML mode. Feel free to update and reopen this PR with that implemented or create a new PR.

@aklinker1 aklinker1 closed this Oct 25, 2025
@namukang
Copy link
Author

namukang commented Oct 25, 2025

@aklinker1 Thanks for the explanation! Tailwind actually fixed that issue so that @theme variables are defined on :host as well: tailwindlabs/tailwindcss#15975

As a result, the CSS variables are defined correctly inside the shadow DOM.

In other words, Tailwind will continue to work if WXT switched to constructing the shadow DOM without building a full HTML document.

Does that affect your thoughts about changing the implementation to using a fragment instead of creating an HTML document?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Why does createIsolatedElement create a complete HTML document

2 participants