-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: isSelfAccepting
? More like isBanishedToTheShadowRealm
#2852
Changes from all commits
80a8d2d
dd00d93
9ffabcc
27b34cf
15dbbf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Fix "isSelfAccepting" exception when using the new @astrojs/react integration in development |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one is surprising! Any idea why this was required / what kind of error message you were seeing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It really is! I was seeing the following when Vite tried to resolve the module. Notice Astro returns a 404 as well: 14:23 PM [vite] Internal server error: Cannot set property 'isSelfAccepting' of undefined
Plugin: vite:import-analysis
File: /Users/benholmes/Sandbox/astro-integration-react/node_modules/.vite/astro_client_load_js.js?v=7a24946c
at ModuleGraph.updateModuleInfo (/Users/benholmes/Sandbox/astro-integration-react/node_modules/vite/dist/node/chunks/dep-9c153816.js:53418:29)
at TransformContext.transform (/Users/benholmes/Sandbox/astro-integration-react/node_modules/vite/dist/node/chunks/dep-9c153816.js:70072:57)
at async Object.transform (/Users/benholmes/Sandbox/astro-integration-react/node_modules/vite/dist/node/chunks/dep-9c153816.js:38334:30)
at async doTransform (/Users/benholmes/Sandbox/astro-integration-react/node_modules/vite/dist/node/chunks/dep-9c153816.js:53030:29)
7:14:23 PM [vite] Internal server error: Cannot set property 'isSelfAccepting' of undefined
Plugin: vite:import-analysis
File: /Users/benholmes/Sandbox/astro-integration-react/node_modules/.vite/astro_client_hmr_js.js?v=7a24946c
at ModuleGraph.updateModuleInfo (/Users/benholmes/Sandbox/astro-integration-react/node_modules/vite/dist/node/chunks/dep-9c153816.js:53418:29)
at TransformContext.transform (/Users/benholmes/Sandbox/astro-integration-react/node_modules/vite/dist/node/chunks/dep-9c153816.js:70072:57)
at async Object.transform (/Users/benholmes/Sandbox/astro-integration-react/node_modules/vite/dist/node/chunks/dep-9c153816.js:38334:30)
at async doTransform (/Users/benholmes/Sandbox/astro-integration-react/node_modules/vite/dist/node/chunks/dep-9c153816.js:53030:29) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ☝️ After tracing Vite's internal logs, there's a different |
||
children: '', | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave a comment here that this is required to prevent bugs? I removed it assuming it was no longer needed for perf, but had no idea it was running defense on bugs!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm curious if it ever was running defense on bugs to be honest. It seemed like a performance choice to me as well. I'll add a note 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!