diff --git a/.changeset/long-spies-check.md b/.changeset/long-spies-check.md new file mode 100644 index 000000000000..4be15dd5fe80 --- /dev/null +++ b/.changeset/long-spies-check.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix isSelfAccepting errors when hydrating JSX components diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index a3feff5aa4b2..f4c18a881b1d 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -5,7 +5,6 @@ import { builtinModules } from 'module'; import { fileURLToPath } from 'url'; import fs from 'fs'; import * as vite from 'vite'; -import { runHookServerSetup } from '../integrations/index.js'; import astroVitePlugin from '../vite-plugin-astro/index.js'; import astroViteServerPlugin from '../vite-plugin-astro-server/index.js'; import astroPostprocessVitePlugin from '../vite-plugin-astro-postprocess/index.js'; diff --git a/packages/astro/src/core/dev/index.ts b/packages/astro/src/core/dev/index.ts index 97be22abd662..8a148d5ce610 100644 --- a/packages/astro/src/core/dev/index.ts +++ b/packages/astro/src/core/dev/index.ts @@ -1,3 +1,5 @@ +import glob from 'fast-glob'; +import path from 'path'; import type { AddressInfo } from 'net'; import type { AstroTelemetry } from '@astrojs/telemetry'; import { performance } from 'perf_hooks'; @@ -33,10 +35,20 @@ export default async function dev(config: AstroConfig, options: DevOptions): Pro await options.telemetry.record([]); 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'); const viteConfig = await createVite( { mode: 'development', server: { host }, + optimizeDeps: { + include: clientRuntimeFilePaths, + } }, { astroConfig: config, logging: options.logging, mode: 'dev' } );