Preoptimize renderers and hydration directives (#3568)

* Preoptimize renderers and hydration directives

* Adds a changeset

* Upgrade to Vite 2.9.12
This commit is contained in:
Matthew Phillips 2022-06-10 12:38:19 -04:00 committed by GitHub
parent d02578fd4c
commit 614769a39b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 14 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes race condition causing the "self accepting" error message

View file

@ -130,7 +130,7 @@
"strip-ansi": "^7.0.1", "strip-ansi": "^7.0.1",
"supports-esm": "^1.0.0", "supports-esm": "^1.0.0",
"tsconfig-resolver": "^3.0.1", "tsconfig-resolver": "^3.0.1",
"vite": "^2.9.10", "vite": "^2.9.12",
"yargs-parser": "^21.0.1", "yargs-parser": "^21.0.1",
"zod": "^3.17.3" "zod": "^3.17.3"
}, },

View file

@ -36,20 +36,23 @@ export default async function dev(config: AstroConfig, options: DevOptions): Pro
config = await runHookConfigSetup({ config, command: 'dev' }); config = await runHookConfigSetup({ config, command: 'dev' });
const { host, port } = config.server; const { host, port } = config.server;
// load client runtime scripts ahead-of-time to fix "isSelfAccepting" bug during HMR // The client entrypoint for renderers. Since these are imported dynamically
const clientRuntimeScripts = await glob( // we need to tell Vite to preoptimize them.
new URL('../../runtime/client/*.js', import.meta.url).pathname const rendererClientEntries = config._ctx.renderers.map(r => r.clientEntrypoint).filter(Boolean) as string[];
);
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');
const viteConfig = await createVite( const viteConfig = await createVite(
{ {
mode: 'development', mode: 'development',
server: { host }, server: { host },
optimizeDeps: { 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' } { astroConfig: config, logging: options.logging, mode: 'dev' }

View file

@ -542,7 +542,7 @@ importers:
strip-ansi: ^7.0.1 strip-ansi: ^7.0.1
supports-esm: ^1.0.0 supports-esm: ^1.0.0
tsconfig-resolver: ^3.0.1 tsconfig-resolver: ^3.0.1
vite: ^2.9.10 vite: ^2.9.12
yargs-parser: ^21.0.1 yargs-parser: ^21.0.1
zod: ^3.17.3 zod: ^3.17.3
dependencies: dependencies:
@ -599,7 +599,7 @@ importers:
strip-ansi: 7.0.1 strip-ansi: 7.0.1
supports-esm: 1.0.0 supports-esm: 1.0.0
tsconfig-resolver: 3.0.1 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 yargs-parser: 21.0.1
zod: 3.17.3 zod: 3.17.3
devDependencies: devDependencies:
@ -13612,8 +13612,8 @@ packages:
fsevents: 2.3.2 fsevents: 2.3.2
dev: false dev: false
/vite/2.9.10_sass@1.52.2: /vite/2.9.12_sass@1.52.2:
resolution: {integrity: sha512-TwZRuSMYjpTurLqXspct+HZE7ONiW9d+wSWgvADGxhDPPyoIcNywY+RX4ng+QpK30DCa1l/oZgi2PLZDibhzbQ==} resolution: {integrity: sha512-suxC36dQo9Rq1qMB2qiRorNJtJAdxguu5TMvBHOc/F370KvqAe9t48vYp+/TbPKRNrMh/J55tOUmkuIqstZaew==}
engines: {node: '>=12.2.0'} engines: {node: '>=12.2.0'}
hasBin: true hasBin: true
peerDependencies: peerDependencies: