Skip to content

feat(hub): cross-iframe dock activation with terminal session focus#103

Merged
antfu merged 1 commit into
mainfrom
feat/hub-dock-activation-terminal-focus
Jul 16, 2026
Merged

feat(hub): cross-iframe dock activation with terminal session focus#103
antfu merged 1 commit into
mainfrom
feat/hub-dock-activation-terminal-focus

Conversation

@antfubot

Copy link
Copy Markdown
Collaborator

Why

Vite DevTools' Rolldown analyzer wants a "Run build with devtools" button that spawns a vite build via ctx.terminals.startChildProcess and then navigates the user straight to that build's Terminals session. Two multi-integration capabilities were missing, and both are dock/terminal-navigation concerns that belong in the hub layer rather than any single integration:

  1. Cross-iframe dock activation — a mounted devframe runs in its own iframe on its own RPC client and had no way to ask the host shell to switch the active dock. The shell's active dock is client-local state with no client API, RPC, or bridge an iframe could use.
  2. Terminal session focus by id — even with Terminals open, there was no way to programmatically select a specific session.

What

Capability A — hub-level cross-iframe dock activation. A new built-in RPC any client may call, hub:docks:activate ({ dockId, params? }), backed by ctx.docks.activate(dockId, params?). The hub broadcasts the request live over a new devframe:docks:activate client function — the client host registers a handler that calls its local switchEntry(dockId), mirroring the existing devframe:messages:updated/devframe:terminals:updated broadcast pattern — and mirrors it into a new devframe:docks:active shared-state slot so a dock that mounts because of the switch still converges on the request. Unknown dock ids degrade to a no-op, warned server-side as DF8107.

Capability B — terminal session focus by id. The Terminals panel reacts to devframe:docks:active: when an activation targets its dock and carries params.sessionId, it focuses that session — whether the panel was already open or mounts in response to the switch. Focus is one-shot; an unknown / not-yet-arrived session id waits for that session to appear (then the user's own tab clicks are honored), and a session that never appears is a no-op (the most-recent-session default stands).

Once released, Vite DevTools can drop its interim Vite-side dock-activation shim and consume hub:docks:activate directly for exact-session focus.

Acceptance criteria

  • A mounted iframe can call hub:docks:activate with { dockId: 'devframes-plugin-terminals', params: { sessionId } } and the host shell switches to Terminals with that exact session focused.
  • Unknown dock ids / session ids degrade gracefully (no crash).
  • Coded diagnostic for the new node-side condition (DF8107, docks sub-range, warn-level + docs page).
  • Docs updated: hub guide (cross-iframe dock activation, built-in RPC, protocol table), terminals plugin (focusing a session), error reference.
  • All gates pass: pnpm lint && pnpm test && pnpm typecheck && pnpm build (671 tests; API snapshots regenerated for the new exports).

Design decisions & open question

  • RPC name. The server RPC is hub:docks:activate (consistent with the other hub:* server built-ins); the server→client broadcast is devframe:docks:activate (consistent with the devframe:* client functions). The proposal suggested a single devframe:docks:activate name — happy to rename the RPC if you'd prefer it to match verbatim.
  • Where params.sessionId is interpreted (open question). Rather than a dedicated devframe:terminals:active slot written by the hub (which would couple the hub to the terminals plugin id), the terminals panel reads the generic devframe:docks:active slot and owns the interpretation of params.sessionId itself — one protocol, no hub→plugin coupling, and it keeps the hub free of terminals-specific knowledge. This is the deliberate default; if you'd rather have a purpose-built devframe:terminals:active slot, that's a small follow-up.

This proposal originated from the Vite DevTools team. This PR was created with the help of an agent.

Let any connected client — including a mounted devframe running in its own
iframe on its own RPC client — steer the host shell's active dock, which is
otherwise client-local and unreachable from a mounted iframe. The terminals
dock reads the activation params to focus a specific session, so a tool can
spawn a build and navigate the user straight to its terminal output.

Co-authored-by: opencode agent
@netlify

netlify Bot commented Jul 16, 2026

Copy link
Copy Markdown

Deploy Preview for devfra ready!

Name Link
🔨 Latest commit 8af8bfe
🔍 Latest deploy log https://app.netlify.com/projects/devfra/deploys/6a58880f5445140008f4f28d
😎 Deploy Preview https://deploy-preview-103--devfra.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@antfu
antfu merged commit 5e5b2c7 into main Jul 16, 2026
12 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.

2 participants