Skip to content

Commit

Permalink
Fix: refusing to accept isSelfAccepting for JSX (#3521)
Browse files Browse the repository at this point in the history
* 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 56530a8.

* refactor: move optimizedeps to dev only

* docs: add comment on why optimizdeps

* nit: indentation
  • Loading branch information
bholmesdev committed Jun 6, 2022
1 parent 574f47e commit 85b9054
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/long-spies-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix isSelfAccepting errors when hydrating JSX components
1 change: 0 additions & 1 deletion packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
12 changes: 12 additions & 0 deletions packages/astro/src/core/dev/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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' }
);
Expand Down

0 comments on commit 85b9054

Please sign in to comment.