Skip to content

Commit

Permalink
triggers HMR for server-only components
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Sullivan committed Apr 15, 2022
1 parent c1336ae commit 2dfdd30
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/astro/src/runtime/client/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if (import.meta.hot) {
// signal to Vite that we accept HMR
import.meta.hot.accept((mod) => mod);
const parser = new DOMParser();
import.meta.hot.on('astro:update', async ({ file }) => {
async function onUpdate(file: string) {
const { default: diff } = await import('micromorph');
// eslint-disable-next-line no-console
console.log(`[vite] hot updated: ${file}`);
Expand All @@ -18,5 +18,14 @@ if (import.meta.hot) {
}
}
diff(document, doc);
}
import.meta.hot.on('astro:update', async ({ file }) => {
await onUpdate(file);
});
import.meta.hot.on('vite:beforeUpdate', async ({ updates }) => {
const astroUpdate = Array.from(updates)
.find((update) => update.acceptedPath.endsWith('.astro'));
if (!astroUpdate) { return; }
await onUpdate(astroUpdate.acceptedPath);
});
}

0 comments on commit 2dfdd30

Please sign in to comment.