Skip to content

Commit

Permalink
readability
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank99 committed Mar 26, 2024
1 parent c806c11 commit 3465877
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ function useShadowRoot(

if (supportsAdoptedStylesheets) {
// create an empty stylesheet and add it to the shadowRoot
const _global = shadow.ownerDocument.defaultView || globalThis;
styleSheet.current = new _global.CSSStyleSheet();
const currentWindow = shadow.ownerDocument.defaultView || globalThis;
styleSheet.current = new currentWindow.CSSStyleSheet();
shadow.adoptedStyleSheets = [styleSheet.current];

// add the CSS immediately to avoid FOUC (one-time)
Expand All @@ -104,13 +104,14 @@ function useShadowRoot(
}

queueMicrotask(() => {
// Flush the state immediately to prevent flash of unslotted light DOM content
ReactDOM.flushSync(() => setShadowRoot(shadow));
});

return () => void setShadowRoot(null);
}, [templateRef, latestCss]);

// Synchronize the CSS contents of existing stylesheet
// Synchronize `css` with contents of the existing stylesheet
useLayoutEffect(() => {
if (css && supportsAdoptedStylesheets) {
styleSheet.current?.replaceSync(css);
Expand Down

0 comments on commit 3465877

Please sign in to comment.