Skip to content

Commit 75a0189

Browse files
committed
Fix restore fn
1 parent 0013ce3 commit 75a0189

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

src/polyfill.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ export async function polyfill(animationFrame?: boolean) {
444444
// pre parse CSS styles that we need to cascade
445445
const cascadeCausedChanges = await cascadeCSS(styleData);
446446
if (cascadeCausedChanges) {
447-
styleData = await transformCSS(styleData);
447+
await transformCSS(styleData);
448448
}
449449
// parse CSS
450450
const { rules, inlineStyles } = await parseCSS(styleData);

src/transform.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,14 @@ export async function transformCSS(
3434
inlineStyles?: Map<HTMLElement, Record<string, string>>,
3535
cleanup = false,
3636
) {
37-
const updatedStyleData: StyleData[] = [];
3837
styleData.forEach(async (data) => {
39-
const { el, css, changed, original } = data;
40-
const updatedObject: StyleData = { el, css, changed: false, original };
41-
if (changed) {
38+
const { el, css, changed, updated } = data;
39+
if (changed && !updated) {
4240
if (el.tagName.toLowerCase() === 'style') {
4341
// Handle inline stylesheets
4442
el.innerHTML = css;
4543
} else if (el.tagName.toLowerCase() === 'link') {
46-
updatedObject.el = await replaceLink(el as HTMLLinkElement, css);
44+
data.el = await replaceLink(el as HTMLLinkElement, css);
4745
} else if (el.hasAttribute(INLINE_STYLES_ID_ATTR)) {
4846
// Handle inline styles
4947
const attr = el.getAttribute(INLINE_STYLES_ID_ATTR);
@@ -62,12 +60,11 @@ export async function transformCSS(
6260
el.setAttribute('style', styles);
6361
}
6462
}
63+
data.updated = true;
6564
}
6665
// Remove no-longer-needed data-attribute
6766
if (cleanup && el.hasAttribute(INLINE_STYLES_ID_ATTR)) {
6867
el.removeAttribute(INLINE_STYLES_ID_ATTR);
6968
}
70-
updatedStyleData.push(updatedObject);
7169
});
72-
return updatedStyleData;
7370
}

src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface StyleData {
3131
url?: URL;
3232
changed?: boolean;
3333
original: string;
34+
updated?: boolean;
3435
}
3536

3637
export const POSITION_ANCHOR_PROPERTY = `--position-anchor-${nanoid(12)}`;

0 commit comments

Comments
 (0)