Skip to content
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

Merged
merged 5 commits into from
Mar 22, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions packages/astro/src/core/render/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ export type ComponentPreload = [SSRLoadedRenderer[], ComponentInstance];
export type RenderResponse = { type: 'html'; html: string } | { type: 'response'; response: Response };

const svelteStylesRE = /svelte\?svelte&type=style/;
const rendererCache = new Map<string, SSRLoadedRenderer['ssr']>();
Copy link
Member

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!

Copy link
Contributor Author

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 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!


async function loadRenderer(viteServer: vite.ViteDevServer, renderer: AstroRenderer): Promise<SSRLoadedRenderer> {
const { url } = await viteServer.moduleGraph.ensureEntryFromUrl(renderer.serverEntrypoint);
const mod = (await viteServer.ssrLoadModule(url)) as { default: SSRLoadedRenderer['ssr'] };
return { ...renderer, ssr: mod.default };

const cachedRenderer = rendererCache.get(url);
if (cachedRenderer) {
return { ...renderer, ssr: cachedRenderer };
} else {
bholmesdev marked this conversation as resolved.
Show resolved Hide resolved
const mod = (await viteServer.ssrLoadModule(url)) as { default: SSRLoadedRenderer['ssr'] };
rendererCache.set(url, mod.default);
return { ...renderer, ssr: mod.default };
}
}

export async function loadRenderers(viteServer: vite.ViteDevServer, astroConfig: AstroConfig): Promise<SSRLoadedRenderer[]> {
Expand Down Expand Up @@ -75,7 +83,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 },
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ After tracing Vite's internal logs, there's a different ?v=XXXXX attached to the end of the URL between calls. It seems to think the file changed even when it hasn't...

children: '',
});
}
Expand Down