Skip to content

Commit

Permalink
Preoptimize renderers and hydration directives (#3568)
Browse files Browse the repository at this point in the history
* Preoptimize renderers and hydration directives

* Adds a changeset

* Upgrade to Vite 2.9.12
  • Loading branch information
matthewp committed Jun 10, 2022
1 parent d02578f commit 614769a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-toes-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes race condition causing the "self accepting" error message
2 changes: 1 addition & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"strip-ansi": "^7.0.1",
"supports-esm": "^1.0.0",
"tsconfig-resolver": "^3.0.1",
"vite": "^2.9.10",
"vite": "^2.9.12",
"yargs-parser": "^21.0.1",
"zod": "^3.17.3"
},
Expand Down
21 changes: 12 additions & 9 deletions packages/astro/src/core/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,23 @@ export default async function dev(config: AstroConfig, options: DevOptions): Pro
config = await runHookConfigSetup({ config, command: 'dev' });
const { host, port } = config.server;

// load client runtime scripts ahead-of-time to fix "isSelfAccepting" bug during HMR
const clientRuntimeScripts = await glob(
new URL('../../runtime/client/*.js', import.meta.url).pathname
);
const clientRuntimeFilePaths = clientRuntimeScripts
.map((script) => `astro/client/${path.basename(script)}`)
// fixes duplicate dependency issue in monorepo when using astro: "workspace:*"
.filter((filePath) => filePath !== 'astro/client/hmr.js');
// The client entrypoint for renderers. Since these are imported dynamically
// we need to tell Vite to preoptimize them.
const rendererClientEntries = config._ctx.renderers.map(r => r.clientEntrypoint).filter(Boolean) as string[];

const viteConfig = await createVite(
{
mode: 'development',
server: { host },
optimizeDeps: {
include: clientRuntimeFilePaths,
include: [
'astro/client/idle.js',
'astro/client/load.js',
'astro/client/visible.js',
'astro/client/media.js',
'astro/client/only.js',
...rendererClientEntries
],
},
},
{ astroConfig: config, logging: options.logging, mode: 'dev' }
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 614769a

Please sign in to comment.