From 76d9590c414c78e3865c30ad63f19d7815e0ecff Mon Sep 17 00:00:00 2001 From: Marius Gundersen Date: Fri, 11 Oct 2024 10:13:55 +0200 Subject: [PATCH 1/2] Replace the without flashing the css --- src/transform.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/transform.ts b/src/transform.ts index 45a86dd..7d6c065 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -25,9 +25,10 @@ export async function transformCSS( const promise = new Promise((res) => { link.onload = res; }); - el.replaceWith(link); + el.insertAdjacentElement('afterend', link); // Wait for new stylesheet to be loaded await promise; + el.remove(); URL.revokeObjectURL(url); updatedObject.el = link; } else if (el.hasAttribute('data-has-inline-styles')) { From 7db4ac9b787974a23fe78d4cb7c4f577f2b3be58 Mon Sep 17 00:00:00 2001 From: Marius Gundersen Date: Mon, 14 Oct 2024 10:44:54 +0200 Subject: [PATCH 2/2] Fixed failing test by inserting the new stylesheet before the old one --- src/transform.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transform.ts b/src/transform.ts index 7d6c065..0f11661 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -25,7 +25,7 @@ export async function transformCSS( const promise = new Promise((res) => { link.onload = res; }); - el.insertAdjacentElement('afterend', link); + el.insertAdjacentElement('beforebegin', link); // Wait for new stylesheet to be loaded await promise; el.remove();