Skip to content

Commit

Permalink
Support multiple constructable stylesheets per shadow DOM element
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewortwein committed Sep 23, 2024
1 parent 24c93f6 commit 3e8743f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/rrweb-snapshot/src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,17 @@ function buildNode(
*/
if (!node.shadowRoot) {
node.attachShadow({ mode: 'open' });
const sheet = new CSSStyleSheet();
// @ts-expect-error TODO
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
sheet.replaceSync(n.chromaticAdoptedStylesheets);
// @ts-expect-error TODO
node.shadowRoot.adoptedStyleSheets = [sheet];
// @ts-expect-error TODO
node.adoptedStyleSheets = [sheet];
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
n.chromaticAdoptedStylesheets.forEach(
// @ts-expect-error TODO
(chromaticAdoptedStylesheet) => {
const styleSheet = new CSSStyleSheet();
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
styleSheet.replaceSync(chromaticAdoptedStylesheet);
node.shadowRoot?.adoptedStyleSheets.push(styleSheet);
},
);
} else {
while (node.shadowRoot.firstChild) {
node.shadowRoot.removeChild(node.shadowRoot.firstChild);
Expand Down

0 comments on commit 3e8743f

Please sign in to comment.