Skip to content

fix(devtools): prefix client module resolution URL with effective Vite base - #1186

Open
a2499123744-del wants to merge 1 commit into
nuxt:mainfrom
a2499123744-del:fix/inspect-component-vite-base
Open

a2499123744-del wants to merge 1 commit into
nuxt:mainfrom
a2499123744-del:fix/inspect-component-vite-base

Conversation

@a2499123744-del

Copy link
Copy Markdown

Fixes #1185

Summary

Clicking Inspect Vue component triggers a dynamic browser import for the bare module specifier vite-plugin-vue-tracer/client/vite-devtools. @vitejs/devtools / @devframes/hub default ctx.staticConfig.dock.clientModuleResolution to '/@id/{specifier}' (and initHub resets it after devtools.setup(ctx) runs), which causes the browser to fetch http://localhost:3000/@id/... at the site root instead of under Nuxt's mounted Vite base (by default /_nuxt/), receiving text/html instead of JavaScript.

This resolves Nuxt's effective client Vite base (viteConfig.server?.base -> viteConfig.base -> joinURL(app.baseURL, app.buildAssetsDir)) and applies <viteBase>@id/{specifier} to ctx.staticConfig.dock.clientModuleResolution on the client DevTools context (including after initHub via provideConnectionMeta and the configureServer post hook).

@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds a utility to resolve client module URLs from Vite base values or Nuxt app paths. The DevTools plugin applies the resolved URL during client setup and refreshes it before connection metadata generation and from a post-order server hook. Tests cover URL normalisation, dock configuration, plugin integration, and SSR setup.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Severity of issue fixed: Medium

Merge Risk: Minimal · up to a7d03

This change makes the component inspector's picker import use the effective Vite base instead of the site root, which addresses the reported failure. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (prefixing the client module resolution URL with the effective Vite base) and the affected package (devtools). The changeset adds resolveClientModuleResolution and applyClientM…
Description check Passed The description states the bug (Inspect Vue component dynamic import resolving at the site root), links issue #1185, and explains the fix: resolving Nuxt's effective client Vite base and applying it t…
Linked Issues check Passed [#1185] requires the Inspect Vue component picker import to use Nuxt's effective Vite base (/_nuxt/ in the reported setup), not the site root. At the reviewed head, `packages/devtools/src/utils/clie…
Out of Scope Changes check Passed All changed files relate to the linked issue. module-main.ts wires the resolution into the DevTools Vite plugin lifecycle. utils/client-module-resolution.ts contains the URL resolution helpers. Th…
Full details: Title check

Explanation

The title names the fix (prefixing the client module resolution URL with the effective Vite base) and the affected package (devtools). The changeset adds resolveClientModuleResolution and applyClientModuleResolution, which compute the Vite base and apply it to ctx.staticConfig.dock.clientModuleResolution, so the title matches the main change. It is a single, concise sentence of 10 words.

Full details: Description check

Explanation

The description states the bug (Inspect Vue component dynamic import resolving at the site root), links issue #1185, and explains the fix: resolving Nuxt's effective client Vite base and applying it to ctx.staticConfig.dock.clientModuleResolution, including after initHub via provideConnectionMeta and the configureServer post hook. This matches the changes in module-main.ts and client-module-resolution.ts.

Full details: Linked Issues check

Explanation

[#1185] requires the Inspect Vue component picker import to use Nuxt's effective Vite base (/_nuxt/ in the reported setup), not the site root. At the reviewed head, packages/devtools/src/utils/client-module-resolution.ts builds &lt;base&gt;@id/{specifier}. Base precedence is viteServerBase, then viteBase, then joinURL(app.baseURL, app.buildAssetsDir), with /_nuxt/ as the default assets directory. applyClientModuleResolution writes this value to ctx.staticConfig.dock.clientModuleResolution. In packages/devtools/src/module-main.ts, the value is applied during devtools.setup(ctx). It is also re-applied in a configureServer post hook and wrapped around host.provideConnectionMeta. That covers the initHub reset described in the issue. The added test file (packages/devtools/test/client-module-resolution.test.ts) covers precedence, slash normalisation, and metadata output. I did not execute the tests or run the browser flow, so runtime behaviour is supported by source inspection only.

Full details: Out of Scope Changes check

Explanation

All changed files relate to the linked issue. module-main.ts wires the resolution into the DevTools Vite plugin lifecycle. utils/client-module-resolution.ts contains the URL resolution helpers. The new test file covers those helpers and the DevTools integration. No unrelated feature, refactor, or dependency change appears in the reviewed summary and the focused module-main.ts diff. The SSR guard (server.config.build?.ssr) and skipInSSR keep the change limited to the client context.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2577051a-a3ad-4590-af68-03982349afda
Commits

Reviewing files that changed from the base of the PR and between ee09f7d and a7d0367.

Files selected for processing: 3

  • packages/devtools/src/module-main.ts
  • packages/devtools/src/utils/client-module-resolution.ts
  • packages/devtools/test/client-module-resolution.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

This branch has not been deployed

No deployments
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.

fix: Inspect Vue component fails because the import URL omits /_nuxt/

1 participant