feat: add StyleSheetManager to inject styles into another document (Electron child windows, iframes, shadow DOM)#65
Open
beautyfree wants to merge 1 commit into
Conversation
Adds a <StyleSheetManager target={node}> provider that routes generated
styles (styled / createGlobalStyles) into the given node's document/root
instead of the main document.head. Enables rendering into Electron child
BrowserWindows, iframes, pop-out windows, and shadow roots.
goober already routes by this.target; this threads a target through a
context into the existing css.apply({ target }) call. No behavior change
when no provider is present.
Closes solidjs#64
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #64.
What
Adds a
StyleSheetManagercomponent that mirrorsstyled-components'<StyleSheetManager target>: everystyledcomponent /createGlobalStylesrendered inside it injects its<style>into the provided node's document/root instead of the maindocument.head.This unblocks rendering into another document — Electron child
BrowserWindows, iframes, pop-outwindow.openwindows, and shadow roots — where the opener document's sheet is not visible, sostyledcomponents currently render unstyled there.How
The internals already thread a
targetinto goober:…but
styledis aProxyovermakeStyledcalled with nothis, so_ctx.targetis alwaysundefinedand there is no public way to set it. This PR adds a context carrying the target, read insideStyled(alongside the existingThemeContextread) and passed to the samecss.apply({ target }). goober routes the sheet to that node's root._ctx.target, falling back to goober's default head.StyleSheetManageris present (target staysundefined).styledandcreateGlobalStyles(the latter renders through the samemakeStyledpath).Scope / follow-up
keyframesandglobare typically called at module scope (outside any component), so they have no context to read and still target the default sheet. Targeting those would need a separate API; left out of this PR to keep it focused on the component-tree caseStyleSheetManagercovers.Tests
test/styleSheetManager.spec.tsx(3 cases): styled rules land in the target document and not the main head;createGlobalStyleshonors the target; absent a provider, styles fall back to the default sheet. All pass.API surface