Skip to content

feat(core): add passive mode for the injected overlay - #465

Merged
antfu merged 8 commits into
mainfrom
busy-cooks-switch
Jul 24, 2026
Merged

feat(core): add passive mode for the injected overlay#465
antfu merged 8 commits into
mainfrom
busy-cooks-switch

Conversation

@antfubot

@antfubotantfubot commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Description

Introduces visibility modes for the embedded (injected) DevTools overlay, modeled on Nuxt DevTools' opt-in reveal. DevTools({ visibility }) accepts 'normal' | 'passive' | 'hidden' (default 'normal').

Modes

  • normal (default) — docks shown immediately.
  • passive — docks hidden; the console prints a hint to reveal them with Shift+Alt+D (⇧ ⌥ D on macOS). Revealing persists a per-project flag in node_modules/.vite-devtools/mode.json, so later dev sessions on this machine start with the docks shown.
  • hidden — docks hidden; the shortcut reveals them for the current session only. Every load starts hidden and nothing is persisted.

Architecture

  • One client entry per mode; node picks one. The injection plugin resolves the mode per HTML request (in transformIndexHtml, so no cache invalidation) and injects one of @vitejs/devtools/client/inject (normal), @vitejs/devtools/client/inject-passive, or @vitejs/devtools/client/inject-hidden. passive upgrades to the normal entry once the project's flag is set (read directly from node_modules).
  • Shared runtime. All three entries call a shared inject/runtime.tsstartDevTools(mode); only passive persists on activate. In-page transitions (activate via shortcut, "Hide DevTools (Passive Mode)" palette command) switch modes without a reload.
  • Persistence channel.POST /__devtools/__mode.json { enabled } writes/clears the flag (served unauthenticated — it only writes a local marker; the docks still require WS trust for project data). hidden never POSTs.
  • Adds diagnostic DTK0033 (mode-persist failure) with docs, a node-side unit test, and updates the Getting Started + Client Context guides.

Verification

  • pnpm typecheck, pnpm test (343 pass), pnpm build, pnpm lint all green.
  • Node-side entry selection was exercised against the core playground dev server. In-browser DOM behavior wasn't exercised (no browser 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 and the unauthenticated persistence endpoint in packages/core/src/node/server.ts.

This PR was created with the help of an agent.

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'`.
@pkg-pr-new

pkg-pr-newBot commented Jul 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vitejs/devtools

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

@vitejs/devtools-kit

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

@vitejs/devtools-oxc

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

@vitejs/devtools-rolldown

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

@vitejs/devtools-vite

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

@vitejs/devtools-vitest

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

commit: 62b9269

# 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)
`hidden` keeps the docks hidden and reveals them with the shortcut for the
current session only — every load starts hidden and nothing is persisted,
unlike `passive` which remembers the reveal. Adds a third client entry
`@vitejs/devtools/client/inject-hidden`; node picks the entry per HTML
request from the resolved visibility.
…oint
- Default `visibility` is now `'normal'` (docks shown immediately); `passive`
and `hidden` are opt-in.
- `/__devtools/__mode.json` is now POST-only persistence: the injection plugin
reads the node_modules flag directly to pick the client entry, so the GET
branch, `isPassive`, and the `visibility` plumbing through the WS/middleware
options are gone.
- Regenerate the export snapshot in the tsnapi 1.2.0 format used by CI.
`DEVTOOLS_MODE_FILENAME` and `DEVTOOLS_HIDE_EVENT` are Vite-DevTools overlay
concerns, not framework-neutral kit surface. Move them to a core-owned
`packages/core/src/constants.ts` shared by the node middleware and the
injected client, and drop them from `@vitejs/devtools-kit/constants`.
@antfu
antfu merged commit c14406b into mainJul 24, 2026
10 checks passed
@antfu
antfu deleted the busy-cooks-switch branch July 24, 2026 10:14
antfubot added a commit to devframes/devframe that referenced this pull request Aug 14, 2026
Ports vitejs/devtools#465 (passive/hidden overlay) to the reference UI,
but as one config field instead of the upstream three-client-entries
approach. `createUi({ embeddedVisibility })` publishes
`ConnectionMeta.configs.ui.embeddedVisibility`:
- `normal` (default) — the floating dock shows immediately.
- `passive` — starts hidden with a console hint; Shift+Alt+D reveals it,
and the reveal persists per-origin so later sessions start shown.
- `hidden` — starts hidden; Shift+Alt+D reveals it for the session only.
Like the float/edge dock mode, it seeds a user-overridable preference:
the config sets the default, the visitor's own reveal/hide wins from then
on. The "Hide" command now conceals (toggleable back via the shortcut)
rather than tearing the dock down for the session.
Built with the help of an agent.
Sign up for freeto 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.

2 participants

@antfubot@antfu