Skip to content

fix(devtools): don't scope dock plugin with { server: false }#1006

Merged
antfu merged 1 commit into
mainfrom
fix/dock-devtools-applyToEnvironment
May 30, 2026
Merged

fix(devtools): don't scope dock plugin with { server: false }#1006
antfu merged 1 commit into
mainfrom
fix/dock-devtools-applyToEnvironment

Conversation

@antfu
Copy link
Copy Markdown
Member

@antfu antfu commented May 30, 2026

Why

Under Nuxt 5 / Vite 8 — and Nuxt 4 with experimental.viteEnvironmentApi: true — the @nuxt/devtools dock entry disappears from the Vite DevTools dock bar. UnoCSS, Unhead, and vite-plugin-inspect register dock entries fine; only ours goes missing.

The cause is the { server: false } scoping passed to addVitePlugin for the dock plugin. When config.environments.{ssr,client} is populated at vite:extend time, @nuxt/kit's addVitePlugin routes the plugin through its applyToEnvironment wrapper. The wrapper is a separate Vite plugin object that does not carry the devtools property, so @vitejs/devtools's plugin filter (viteConfig.plugins.filter(p => "devtools" in p)) silently drops it and the dock setup(ctx) never runs.

The original "server Vite overwrites client Vite RPC" race that motivated the scoping in #977 is already handled by the if (devtoolsKitCtx) return guard inside connectDevToolsKit itself, so the plugin-level scoping was redundant safety that turned into a regression vector.

Dropping the scoping restores the dock entry in all Nuxt 4/5 × SSR/SPA combinations without re-introducing the RPC race.

A new playgrounds/spa (with ssr: false and experimental.viteEnvironmentApi: true) is added to the e2e matrix as a hard regression test: under this combo on Nuxt 4 the bug reproduces identically to the Nuxt 5 SPA scenario from the report, so the existing iframe.spec.ts fixture goes RED whenever { server: false } sneaks back in.

This PR was created with the help of an agent.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 30, 2026

Deploying nuxt-devtools with  Cloudflare Pages  Cloudflare Pages

Latest commit: b2665eb
Status: ✅  Deploy successful!
Preview URL: https://c4c25281.nuxt-devtools.pages.dev
Branch Preview URL: https://fix-dock-devtools-applytoenv.nuxt-devtools.pages.dev

View logs

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 79b013d9-147c-4363-af3f-c2b42f78ce36

📥 Commits

Reviewing files that changed from the base of the PR and between 5d9f2b6 and b2665eb.

📒 Files selected for processing (10)
  • .gitignore
  • package.json
  • packages/devtools/src/module-main.ts
  • playgrounds/spa/.npmrc
  • playgrounds/spa/app.vue
  • playgrounds/spa/nuxt.config.ts
  • playgrounds/spa/package.json
  • playgrounds/spa/public/empty.txt
  • playgrounds/spa/tsconfig.json
  • tests/e2e/playwright.config.ts
✅ Files skipped from review due to trivial changes (2)
  • .gitignore
  • playgrounds/spa/.npmrc
🚧 Files skipped from review as they are similar to previous changes (6)
  • playgrounds/spa/tsconfig.json
  • packages/devtools/src/module-main.ts
  • playgrounds/spa/package.json
  • package.json
  • playgrounds/spa/nuxt.config.ts
  • playgrounds/spa/app.vue

📝 Walkthrough

Walkthrough

This PR adds a new SPA playground (Nuxt config with ssr: false, package.json, .npmrc, tsconfig, and an app.vue), removes the { server: false } option from the DevTools Vite plugin registration with explanatory comments, and updates e2e tooling: the Playwright PLAYGROUNDS list and the top-level test:e2e:prebuild script to build the SPA playground.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main fix: removing { server: false } scoping from the dock plugin registration, which is the core change in packages/devtools/src/module-main.ts.
Description check ✅ Passed The description is directly related to the changeset, providing detailed context about why the dock plugin scoping is being removed and explaining the regression it was causing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/dock-devtools-applyToEnvironment

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/devtools/src/module-main.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

playgrounds/spa/app.vue

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

playgrounds/spa/nuxt.config.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

  • 1 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Under Nuxt 5 / Vite 8 (and Nuxt 4 with `experimental.viteEnvironmentApi`),
`addVitePlugin(plugin, { server: false })` makes `@nuxt/kit` wrap the
plugin in an `applyToEnvironment` shell. That wrapper plugin lacks a
`devtools` property, so `@vitejs/devtools`'s plugin filter
(`viteConfig.plugins.filter(p => "devtools" in p)`) silently drops it
and the Nuxt DevTools dock entry never appears in the Vite DevTools
dock bar.

The original client-vs-server RPC race that motivated the scoping in
b5f9f8a is already prevented by the `if (devtoolsKitCtx) return`
guard inside `connectDevToolsKit`, so the plugin-level scoping is
unnecessary.

Adds a `spa` playground (`ssr: false` + `experimental.viteEnvironmentApi: true`)
to the e2e matrix as a hard regression test: under this combo on Nuxt 4 the
dock-missing bug reproduces identically to the Nuxt 5 SPA scenario the
report was filed against, so the existing `iframe.spec.ts` fixture
turns RED when `{ server: false }` is reintroduced.
@antfu antfu force-pushed the fix/dock-devtools-applyToEnvironment branch from 5d9f2b6 to b2665eb Compare May 30, 2026 05:08
@antfu antfu merged commit b2665eb into main May 30, 2026
5 of 8 checks passed
@antfu antfu deleted the fix/dock-devtools-applyToEnvironment branch May 30, 2026 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant