From 38b6702191e8ae4eee589bc1c8f900f408829849 Mon Sep 17 00:00:00 2001 From: barry <91018388+barry166@users.noreply.github.com> Date: Sun, 26 Jul 2026 12:21:34 +0800 Subject: [PATCH] Prevent Vue devtools from crashing Vite 8 dev sessions Vite 8 processes Astro SSR modules before the client CSS cache is initialized. Confining Vue devtools plugins to the client environment preserves their browser behavior while keeping their styled overlay out of SSR. Constraint: Vite 8 dev environments initialize CSS state per environment Rejected: Disable Vue devtools entirely | removes a supported development feature Confidence: high Scope-risk: narrow Directive: Keep browser-only devtools plugins out of Astro SSR environments Tested: @astrojs/vue build; 24 integration tests; Biome; diff check Not-tested: Browser interaction with the devtools overlay --- .changeset/friendly-vue-devtools.md | 5 +++++ packages/integrations/vue/src/index.ts | 17 +++++++++++---- packages/integrations/vue/test/basics.test.ts | 21 +++++++++++++++++-- .../vue/test/fixtures/basics/astro.config.mjs | 2 +- 4 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 .changeset/friendly-vue-devtools.md diff --git a/.changeset/friendly-vue-devtools.md b/.changeset/friendly-vue-devtools.md new file mode 100644 index 000000000000..49bde506b36c --- /dev/null +++ b/.changeset/friendly-vue-devtools.md @@ -0,0 +1,5 @@ +--- +'@astrojs/vue': patch +--- + +Fix dev server crashes when Vue devtools are enabled with Vite 8. diff --git a/packages/integrations/vue/src/index.ts b/packages/integrations/vue/src/index.ts index c74040f729e8..ee380e8c8c1e 100644 --- a/packages/integrations/vue/src/index.ts +++ b/packages/integrations/vue/src/index.ts @@ -136,13 +136,22 @@ async function getViteConfiguration( if (command === 'dev' && options?.devtools) { const vueDevTools = (await import('vite-plugin-vue-devtools')).default; - const devToolsOptions = typeof options.devtools === 'object' ? options.devtools : {}; - plugins.push( - configEnvironmentPlugin(), + const devToolsOptions = + typeof options.devtools === 'object' && options.devtools ? options.devtools : {}; + const devToolsPlugins = ( vueDevTools({ ...devToolsOptions, appendTo: VIRTUAL_MODULE_ID, - }), + }) as Plugin[] | Plugin[][] + ).flat(); + plugins.push( + configEnvironmentPlugin(), + ...devToolsPlugins.map((plugin) => ({ + ...plugin, + applyToEnvironment: ( + environment: Parameters>[0], + ) => environment.name === 'client', + })), ); } diff --git a/packages/integrations/vue/test/basics.test.ts b/packages/integrations/vue/test/basics.test.ts index e1dd222c8fbc..dd038e2a5bf3 100644 --- a/packages/integrations/vue/test/basics.test.ts +++ b/packages/integrations/vue/test/basics.test.ts @@ -1,7 +1,7 @@ import * as assert from 'node:assert/strict'; -import { before, describe, it } from 'node:test'; +import { after, before, describe, it } from 'node:test'; import { parseHTML } from 'linkedom'; -import { type Fixture, loadFixture } from './test-utils.ts'; +import { type DevServer, type Fixture, loadFixture } from './test-utils.ts'; describe('Basics', () => { let fixture: Fixture; @@ -47,4 +47,21 @@ describe('Basics', () => { const allPreValues = [...document.querySelectorAll('pre')].map((e) => e.textContent); assert.deepEqual(allPreValues, ['2345', '0', '1', '1', '1', '10', '100', '1000']); }); + + describe('dev', () => { + let devServer: DevServer; + + before(async () => { + devServer = await fixture.startDevServer(); + }); + + after(async () => { + await devServer.stop(); + }); + + it('starts with Vue devtools enabled', async () => { + const response = await fixture.fetch('/'); + assert.equal(response.status, 200); + }); + }); }); diff --git a/packages/integrations/vue/test/fixtures/basics/astro.config.mjs b/packages/integrations/vue/test/fixtures/basics/astro.config.mjs index 51dcc333227c..cb2602affbca 100644 --- a/packages/integrations/vue/test/fixtures/basics/astro.config.mjs +++ b/packages/integrations/vue/test/fixtures/basics/astro.config.mjs @@ -2,5 +2,5 @@ import vue from '@astrojs/vue'; import { defineConfig } from 'astro/config'; export default defineConfig({ - integrations: [vue({ jsx: true })], + integrations: [vue({ devtools: true, jsx: true })], })