From 6e07bc5d087b4cf62a4aad886f421b93e7241d1c Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Thu, 4 Aug 2022 14:31:58 -0500 Subject: [PATCH 1/3] fix(hmr): remove SSR styles once HMR styles are injected --- packages/astro/src/runtime/client/hmr.ts | 47 +++++++++++++++++------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/packages/astro/src/runtime/client/hmr.ts b/packages/astro/src/runtime/client/hmr.ts index ba17fc526b6c..f3a3074f3a46 100644 --- a/packages/astro/src/runtime/client/hmr.ts +++ b/packages/astro/src/runtime/client/hmr.ts @@ -1,21 +1,24 @@ /// + if (import.meta.hot) { - import.meta.hot.on('vite:beforeUpdate', async (payload) => { - for (const file of payload.updates) { - if ( - file.acceptedPath.includes('svelte&type=style') || - file.acceptedPath.includes('astro&type=style') - ) { - // This will only be called after the svelte component has hydrated in the browser. - // At this point Vite is tracking component style updates, we need to remove - // styles injected by Astro for the component in favor of Vite's internal HMR. - const injectedStyle = document.querySelector( - `style[data-astro-injected="${file.acceptedPath}"]` - ); - if (injectedStyle) { - injectedStyle.parentElement?.removeChild(injectedStyle); + // Vite injects `