0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00

Fix: isSelfAccepting? More like isBanishedToTheShadowRealm (#2852)

* fix: restore renderer caching strategy

* fix: restore old URL constructor for HMR

* docs: comment why we need the rendererCache

* refactor: remove needless "else"

* chore: changeset
This commit is contained in:
Ben Holmes 2022-03-21 23:14:58 -04:00 committed by GitHub
parent b6553cfdc1
commit 96372e6beb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix "isSelfAccepting" exception when using the new @astrojs/react integration in development

View file

@ -40,10 +40,21 @@ export type ComponentPreload = [SSRLoadedRenderer[], ComponentInstance];
export type RenderResponse = { type: 'html'; html: string } | { type: 'response'; response: Response };
const svelteStylesRE = /svelte\?svelte&type=style/;
// Cache renderers to avoid re-resolving the module using Vite's `ssrLoadModule`
// This prevents an odd exception trying to resolve the same server-side module
// Multiple times. See `isSelfAccepting` issue: https://github.com/withastro/astro/pull/2852
const rendererCache = new Map<string, SSRLoadedRenderer['ssr']>();
async function loadRenderer(viteServer: vite.ViteDevServer, renderer: AstroRenderer): Promise<SSRLoadedRenderer> {
const { url } = await viteServer.moduleGraph.ensureEntryFromUrl(renderer.serverEntrypoint);
const cachedRenderer = rendererCache.get(url);
if (cachedRenderer) {
return { ...renderer, ssr: cachedRenderer };
}
const mod = (await viteServer.ssrLoadModule(url)) as { default: SSRLoadedRenderer['ssr'] };
rendererCache.set(url, mod.default);
return { ...renderer, ssr: mod.default };
}
@ -75,7 +86,7 @@ export async function render(renderers: SSRLoadedRenderer[], mod: ComponentInsta
children: '',
});
scripts.add({
props: { type: 'module', src: '/@id/astro/client/hmr.js' },
props: { type: 'module', src: new URL('../../../runtime/client/hmr.js', import.meta.url).pathname },
children: '',
});
}