From 85b905495d4bc538686109e056a821e35139c111 Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Mon, 6 Jun 2022 09:27:35 -0400 Subject: [PATCH] Fix: refusing to accept `isSelfAccepting` for JSX (#3521) * fix: generate client directive scripts from metadata * chore: changeset * feat: add all runtime client scripts to optimized deps * fix: remove hmr.js from optimized deps (monorepo-specific issue) * Revert "fix: generate client directive scripts from metadata" This reverts commit 56530a86efb6ac62eecccb6403a35b495c75a9d3. * refactor: move optimizedeps to dev only * docs: add comment on why optimizdeps * nit: indentation --- .changeset/long-spies-check.md | 5 +++++ packages/astro/src/core/create-vite.ts | 1 - packages/astro/src/core/dev/index.ts | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .changeset/long-spies-check.md diff --git a/.changeset/long-spies-check.md b/.changeset/long-spies-check.md new file mode 100644 index 000000000..4be15dd5f --- /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 a3feff5aa..f4c18a881 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 97be22abd..8a148d5ce 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' } );