@@ -3,7 +3,8 @@ import 'construct-style-sheets-polyfill';
33import React from 'react' ;
44import { createRoot } from 'react-dom/client' ;
55import { Provider } from 'react-redux' ;
6- import { twind , config , cssom , observe } from './twind' ;
6+ import { debounce } from 'lodash-es' ;
7+ import { twind , config , cssom , observe , stringify } from './twind' ;
78import { proxyStore } from '../app/proxyStore' ;
89import Content from './Content' ;
910
@@ -14,16 +15,34 @@ proxyStore.ready().then(() => {
1415 document . body . append ( contentRoot ) ;
1516
1617 const shadowRoot = contentRoot . attachShadow ( { mode : 'open' } ) ;
18+ const sheet = cssom ( new CSSStyleSheet ( ) ) ;
19+
20+ // shadowRoot.adoptedStyleSheet bug in firefox
21+ // see: https://bugzilla.mozilla.org/show_bug.cgi?id=1827104
22+ if ( navigator ?. userAgent . includes ( 'Firefox' ) ) {
23+ const style = document . createElement ( 'style' ) ;
24+ const debouncedSyncCss = debounce ( ( ) => {
25+ style . textContent += stringify ( sheet . target ) ;
26+ } , 100 ) ;
27+
28+ const originalSheetInsert = sheet . insert ;
29+ ( sheet . insert as typeof originalSheetInsert ) = ( ...params ) => {
30+ originalSheetInsert ( ...params ) ;
31+ debouncedSyncCss ( ) ;
32+ } ;
33+ shadowRoot . appendChild ( style ) ;
34+ } else {
35+ shadowRoot . adoptedStyleSheets = [ sheet . target ] ;
36+ }
37+
38+ const tw = twind ( config , sheet ) ;
39+ observe ( tw , shadowRoot ) ;
40+
1741 const shadowWrapper = document . createElement ( 'div' ) ;
1842 shadowWrapper . id = 'root' ;
1943 shadowWrapper . style . display = 'contents' ;
2044 shadowRoot . appendChild ( shadowWrapper ) ;
2145
22- const sheet = cssom ( new CSSStyleSheet ( ) ) ;
23- const tw = twind ( config , sheet ) ;
24- shadowRoot . adoptedStyleSheets = [ sheet . target ] ;
25- observe ( tw , shadowRoot ) ;
26-
2746 createRoot ( shadowWrapper ) . render (
2847 < React . StrictMode >
2948 < Provider store = { proxyStore } >
0 commit comments