Skip to content

feat(core): mirror the dock panel's localStorage state into shared state - #525

Open
dvcolomban wants to merge 2 commits into
vitejs:mainfrom
dvcolomban:dvcol/dock-panel-shared-state
Open

feat(core): mirror the dock panel's localStorage state into shared state#525
dvcolomban wants to merge 2 commits into
vitejs:mainfrom
dvcolomban:dvcol/dock-panel-shared-state

Conversation

@dvcolomban

@dvcolomban dvcolomban commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Why

panelStore (the vite-devtools-dock-state key) is purely browser-local today — nothing on the Node/server side can see it, including whether the panel is even open. Any Node-side plugin that wants to react to dock UI state — gate some behavior on visibility, log usage, sync it elsewhere — has nothing to observe.

What changed

  • Wraps the existing useLocalStorage call with a small generic helper, useLocalStorageSharedState, that mirrors the whole value into rpc.sharedState under the same key. Shared-state mutations already round-trip through the server before reappearing locally, so that's the entire mechanism — no new dock-entry field, no client-script gating, no RPC command, no trust handshake.
  • Mirrors the whole object rather than cherry-picking open: it's already one useLocalStorage-backed, fully serializable, browser-local singleton (not per-tab), so a second, narrower key for just one field would just be a redundant place for that field to live.

Known limitation, flagging it rather than hiding it: shared state is one authoritative value, last-mutation-wins — with two tabs open, a Node-side consumer watching e.g. open sees whichever tab mutated most recently. Per-connection keying would need a way to garbage-collect a disconnected tab's entry, and nothing in the public API exposes that today, so I went with the simpler singleton.

Linked Issues

Additional context

Verified with pnpm build, pnpm test (5 new tests for the helper, 384 passing total), pnpm typecheck, pnpm lint — all green.

`panelStore` (`vite-devtools-dock-state`) is purely browser-local
today — a node-side plugin has no way to observe it, including whether
the panel is even open. Wrap the existing `useLocalStorage` call with
a small generic helper, `useLocalStorageSharedState`, that mirrors the
whole value into `rpc.sharedState` under the same key: shared-state
mutations already round-trip through the server before reappearing
locally, so this is the entire mechanism — no new dock-entry field, no
client-script gating, no RPC command, no trust handshake.

Deliberately mirrors the whole object rather than cherry-picking
`open`: it's already one `useLocalStorage`-backed, fully serializable,
browser-local singleton (not per-tab) — a second, narrower key for one
of its fields would just be a redundant place for that field to live.

Known, accepted limitation: shared state is one authoritative value,
last-mutation-wins, so a node-side consumer watching `open` across two
open tabs sees whichever one mutated most recently. Per-connection
keying would need a way to garbage-collect a disconnected tab's entry,
which nothing in the public API exposes today — revisit if that changes.
@pkg-pr-new

pkg-pr-new Bot commented Aug 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vitejs/devtools

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

@vitejs/devtools-kit

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

@vitejs/devtools-oxc

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

@vitejs/devtools-rolldown

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

@vitejs/devtools-vite

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

@vitejs/devtools-vitest

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

commit: db5b086

@dvcolomban
dvcolomban marked this pull request as ready for review August 10, 2026 15:17
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