fix: HMR regression (#1858)
* fix: HMR regression * fix: inject HMR script directly
This commit is contained in:
parent
e1e12eb7fe
commit
dbc49ed62c
3 changed files with 18 additions and 2 deletions
5
.changeset/beige-hairs-design.md
Normal file
5
.changeset/beige-hairs-design.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix HMR regression
|
|
@ -22,7 +22,7 @@ const ALWAYS_EXTERNAL = new Set([
|
||||||
'shiki',
|
'shiki',
|
||||||
'shorthash',
|
'shorthash',
|
||||||
'unified',
|
'unified',
|
||||||
'whatwg-url',
|
'whatwg-url'
|
||||||
]);
|
]);
|
||||||
const ALWAYS_NOEXTERNAL = new Set([
|
const ALWAYS_NOEXTERNAL = new Set([
|
||||||
'astro', // This is only because Vite's native ESM doesn't resolve "exports" correctly.
|
'astro', // This is only because Vite's native ESM doesn't resolve "exports" correctly.
|
||||||
|
|
|
@ -225,7 +225,9 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO
|
||||||
tags.push({
|
tags.push({
|
||||||
tag: 'script',
|
tag: 'script',
|
||||||
attrs: { type: 'module' },
|
attrs: { type: 'module' },
|
||||||
children: `import 'astro/runtime/client/hmr.js';`,
|
// HACK: inject the direct contents of our `astro/runtime/client/hmr.js` to ensure
|
||||||
|
// `import.meta.hot` is properly handled by Vite
|
||||||
|
children: await getHmrScript(),
|
||||||
injectTo: 'head',
|
injectTo: 'head',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -255,6 +257,15 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let hmrScript: string;
|
||||||
|
async function getHmrScript() {
|
||||||
|
if (hmrScript) return hmrScript;
|
||||||
|
const filePath = fileURLToPath(new URL('../../runtime/client/hmr.js', import.meta.url));
|
||||||
|
const content = await fs.promises.readFile(filePath);
|
||||||
|
hmrScript = content.toString();
|
||||||
|
return hmrScript;
|
||||||
|
}
|
||||||
|
|
||||||
export async function ssr(ssrOpts: SSROptions): Promise<string> {
|
export async function ssr(ssrOpts: SSROptions): Promise<string> {
|
||||||
try {
|
try {
|
||||||
const [renderers, mod] = await preload(ssrOpts);
|
const [renderers, mod] = await preload(ssrOpts);
|
||||||
|
|
Loading…
Add table
Reference in a new issue