Skip to content

fix(core): serve devtools under base path - #662

Merged
webfansplz merged 4 commits into
vitejs:mainfrom
huang-julien:fix/base_path
Dec 3, 2026
Merged

webfansplz merged 4 commits into
vitejs:mainfrom
huang-julien:fix/base_path

Conversation

@huang-julien

@huang-julien huang-julien commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

Hey 👋

This PR makes the dev-mode embedded loader respect Vite's base and makes the hub answer under base too.

Why

When working on the Storybook integration, I noticed that the Storybook preview was mounting the host app's dock instead of its own which ends up in an infinite reload.

Storybook's Vite plugin starts a second Vite server in middlewareMode with base: '/storybook/', and the parent server strips /storybook before handing requests over. That inner server has its own hub at /storybook/__devtools/, but its pages still load /__devtools/embedded.js, which is the outer hub (or a 404 if there's none). If the host registers an iframe dock pointing at Storybook, it nests itself endlessly.

The issue lies in DevToolsInjection: it only adds config.base when config.command === 'build', so in serve mode the loader always points at the root.

Reporudction

Screen.Recording.2026-12-02.at.13.21.37.mov
git clone https://github.com/storybookjs/mealdrop.git
git checkout julien/vite-plugin-devtools
yarn 
yarn start

open the devtools dock of storybook. it will be linked to the actual devtool of the app rather thean the nested storybook.

Fix screenshot

image

You can see that the devtools in storybook isn't the one from the app as it doesn't dock Storybook within Storybook

Linked Issues

Additional context

@pkg-pr-new

pkg-pr-new Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vitejs/devtools

npm i https://pkg.pr.new/@vitejs/devtools@662

@vitejs/devtools-kit

npm i https://pkg.pr.new/@vitejs/devtools-kit@662

@vitejs/devtools-oxc

npm i https://pkg.pr.new/@vitejs/devtools-oxc@662

@vitejs/devtools-rolldown

npm i https://pkg.pr.new/@vitejs/devtools-rolldown@662

@vitejs/devtools-vite

npm i https://pkg.pr.new/@vitejs/devtools-vite@662

@vitejs/devtools-vite-task

npm i https://pkg.pr.new/@vitejs/devtools-vite-task@662

@vitejs/devtools-vitest

npm i https://pkg.pr.new/@vitejs/devtools-vitest@662

commit: fb346b3

@webfansplz webfansplz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking this down! The root cause makes sense, and mounting the hub under base is needed too, otherwise regular base: '/foo/' projects would break. In a local nested setup with two Vite servers, the loader now points to the inner hub.

I think the fix can be smaller, though. The main parts to keep are the loader base, the extra hub mount, and the /@id/ prefix. I left some suggestions inline.

Could you also add a test for the nested case, with the inner server in middlewareMode and the parent stripping the prefix? The current tests only cover a standalone server.

Dock iframes and icons still use root paths, so a nested dock loads them from the outer server. That's not new in this PR, so we can handle it separately.

Comment thread packages/core/src/node/server.ts Resolved
Comment thread packages/core/src/node/server.ts Resolved
@webfansplz webfansplz changed the title fix(node): serve devtools under base path fix(core): serve devtools under base path Dec 3, 2026
@webfansplz
webfansplz merged commit 8861ea4 into vitejs:main Dec 3, 2026
7 checks passed
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.

3 participants