feat(core): add passive mode for the injected overlay#465
Open
antfubot wants to merge 4 commits into
Open
Conversation
The embedded DevTools client now starts in passive mode by default: the floating docks stay hidden and the console prints a hint to reveal them with Shift+Alt+D. Activating persists a per-project flag in node_modules, so later dev sessions on the machine boot straight into normal mode. A "Hide DevTools" command returns to passive mode; `passive: false` opts out.
Replace the boolean `passive` DevTools option with a clearer `visibility: 'passive' | 'normal'` enum, defaulting to `'passive'`.
@vitejs/devtools
@vitejs/devtools-kit
@vitejs/devtools-oxc
@vitejs/devtools-rolldown
@vitejs/devtools-vite
@vitejs/devtools-vitest
commit: |
# Conflicts: # packages/core/src/client/webcomponents/state/context.ts
Move the passive-vs-normal decision to the node side: the injection plugin now picks which client entry to inject per HTML request from the project's resolved visibility (and the persisted flag), instead of one client that fetches its mode at runtime. - `@vitejs/devtools/client/inject` — normal, mounts the docks immediately - `@vitejs/devtools/client/inject-passive` — passive, hint + shortcut - shared runtime handles in-page activate / hide transitions (no reload)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Introduces a passive mode for the embedded (injected) DevTools overlay, modeled on Nuxt DevTools' opt-in reveal.
What changed
DevTools()plugin resolves the project's visibility per HTML request and injects one of:@vitejs/devtools/client/inject— normal: mounts the floating docks immediately.@vitejs/devtools/client/inject-passive— passive (default): keeps the docks hidden and prints a styled console hint to reveal them withShift+Alt+D(⇧ ⌥ Don macOS).node_modules/.vite-devtools/mode.json. Since the entry is chosen node-side per request, the next full load injects the normal entry directly. The flag lives undernode_modules(not Vite'scacheDir) sovite --forcedoesn't reset it.inject/runtime.ts) backs both entries, so activating (shortcut) and the "Hide DevTools (Passive Mode)" palette command switch modes in-page without a reload.POST /__devtools/__mode.json { enabled }writes/clears the flag (served unauthenticated — it only toggles the local overlay and writes a marker; the docks still require WS trust for project data).DevTools({ visibility: 'normal' })always injects the normal entry (visibility: 'passive' | 'normal', default'passive').DTK0033(mode-persist failure) with docs, a node-side unit test, and updates the Getting Started + Client Context guides.Verification
pnpm typecheck,pnpm test(338 pass),pnpm build,pnpm lintall green.inject-passive;POST {enabled:true}writes the flag and the next HTML load injectsinject(normal);POST {enabled:false}reverts. Injection chain (HTML → html-proxy → virtual module → entry) confirmed for both entries. In-browser DOM behavior wasn't exercised (no browser available in the sandbox).Linked Issues
Additional context
Reviewers may want to focus on the node-side entry selection in
packages/core/src/node/plugins/injection.ts(decision made intransformIndexHtml, re-evaluated per request so no cache invalidation is needed) and the unauthenticated persistence endpoint inpackages/core/src/node/server.ts.This PR was created with the help of an agent.