From 614769a39b4976dc292d1ed7fa1735811c0bdb8c Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 10 Jun 2022 12:38:19 -0400 Subject: [PATCH] Preoptimize renderers and hydration directives (#3568) * Preoptimize renderers and hydration directives * Adds a changeset * Upgrade to Vite 2.9.12 --- .changeset/modern-toes-glow.md | 5 +++++ packages/astro/package.json | 2 +- packages/astro/src/core/dev/index.ts | 21 ++++++++++++--------- pnpm-lock.yaml | 8 ++++---- 4 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 .changeset/modern-toes-glow.md diff --git a/.changeset/modern-toes-glow.md b/.changeset/modern-toes-glow.md new file mode 100644 index 000000000000..cfab01c822b9 --- /dev/null +++ b/.changeset/modern-toes-glow.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes race condition causing the "self accepting" error message diff --git a/packages/astro/package.json b/packages/astro/package.json index cdecaf45f06a..d58c5a18937e 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -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" }, diff --git a/packages/astro/src/core/dev/index.ts b/packages/astro/src/core/dev/index.ts index 37a0e63ee9b4..7c25bb17ff67 100644 --- a/packages/astro/src/core/dev/index.ts +++ b/packages/astro/src/core/dev/index.ts @@ -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' } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d86bd07f1dd7..f51f66a14a7e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -542,7 +542,7 @@ importers: 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 dependencies: @@ -599,7 +599,7 @@ importers: strip-ansi: 7.0.1 supports-esm: 1.0.0 tsconfig-resolver: 3.0.1 - vite: 2.9.10_sass@1.52.2 + vite: 2.9.12_sass@1.52.2 yargs-parser: 21.0.1 zod: 3.17.3 devDependencies: @@ -13612,8 +13612,8 @@ packages: fsevents: 2.3.2 dev: false - /vite/2.9.10_sass@1.52.2: - resolution: {integrity: sha512-TwZRuSMYjpTurLqXspct+HZE7ONiW9d+wSWgvADGxhDPPyoIcNywY+RX4ng+QpK30DCa1l/oZgi2PLZDibhzbQ==} + /vite/2.9.12_sass@1.52.2: + resolution: {integrity: sha512-suxC36dQo9Rq1qMB2qiRorNJtJAdxguu5TMvBHOc/F370KvqAe9t48vYp+/TbPKRNrMh/J55tOUmkuIqstZaew==} engines: {node: '>=12.2.0'} hasBin: true peerDependencies: