Skip to content

Commit e35a004

Browse files
authored
refactor(runtime): don't recreate adoptedStyleSheets (#6321)
1 parent 7132259 commit e35a004

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/runtime/styles.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ export const addStyle = (styleContainerNode: any, cmpMeta: d.ComponentRuntimeMet
120120
*/
121121
const stylesheet = new CSSStyleSheet();
122122
stylesheet.replaceSync(style);
123-
styleContainerNode.adoptedStyleSheets = [stylesheet, ...styleContainerNode.adoptedStyleSheets];
123+
124+
/**
125+
* > If the array needs to be modified, use in-place mutations like push().
126+
* https://developer.mozilla.org/en-US/docs/Web/API/Document/adoptedStyleSheets
127+
*/
128+
styleContainerNode.adoptedStyleSheets.unshift(stylesheet);
124129
} else {
125130
/**
126131
* If a scoped component is used within a shadow root and constructable stylesheets are
@@ -162,7 +167,11 @@ export const addStyle = (styleContainerNode: any, cmpMeta: d.ComponentRuntimeMet
162167
}
163168
}
164169
} else if (BUILD.constructableCSS && !styleContainerNode.adoptedStyleSheets.includes(style)) {
165-
styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
170+
/**
171+
* > If the array needs to be modified, use in-place mutations like push().
172+
* https://developer.mozilla.org/en-US/docs/Web/API/Document/adoptedStyleSheets
173+
*/
174+
styleContainerNode.adoptedStyleSheets.push(style);
166175
}
167176
}
168177
return scopeId;

0 commit comments

Comments
 (0)