Is your feature request related to a problem? Please describe.
I've been trying to integrate stitches into shadow DOM, and have been running into issues since stitches assumes a global stylesheet with no easy way to insert it into a shadow root.
Describe the solution you'd like
Stitches adopt Constructable Stylesheets which can be used in the following manner:
Stitches can check if constructable stylesheets are available (Safari) or fallback to current behavior
createStitches provides a CSSStyleSheet object or CSSStyleSheet[] array
Stitches can apply styles to document via document.adoptedStyles.push() or user can opt out in the init to apply that same instance across roots themselves
when stitches modifies the styles it calls CSSStyleSheet.replaceSync() or CSSStyleSheet.replace()
Describe alternatives you've considered
I've been able to have 2 not-great solutions:
[link] createStitches, then statically define styles, then use the SSR function to statically inject the string into the shadow root's styles
[link] Create stitches once I attach the shadow root and use the undocumented root init to point it to the shadow root
workaround 1 won't update the styles since it's static but it's generally performant and has a shared createStitches across the app
workaround 2 creates multiple createStitches and might break things like theming across the app.
Additional context
way-earlier in the constructable stylesheets spec emotion had a look at it for performance reasons
Is your feature request related to a problem? Please describe.
I've been trying to integrate stitches into shadow DOM, and have been running into issues since stitches assumes a global stylesheet with no easy way to insert it into a shadow root.
Describe the solution you'd like
Stitches adopt Constructable Stylesheets which can be used in the following manner:
createStitches
provides aCSSStyleSheet
object orCSSStyleSheet[]
arraydocument
viadocument.adoptedStyles.push()
or user can opt out in the init to apply that same instance across roots themselvesCSSStyleSheet.replaceSync()
orCSSStyleSheet.replace()
Describe alternatives you've considered
I've been able to have 2 not-great solutions:
root
init to point it to the shadow rootworkaround 1 won't update the styles since it's static but it's generally performant and has a shared
createStitches
across the appworkaround 2 creates multiple
createStitches
and might break things like theming across the app.Additional context
.push()
ed to