Skip to content

refactor: shared webview IPC helpers with enforced exhaustiveness#911

Draft
EhabY wants to merge 2 commits intofeat/speedtest-visualization-888from
feat/webview-ipc-refactor
Draft

refactor: shared webview IPC helpers with enforced exhaustiveness#911
EhabY wants to merge 2 commits intofeat/speedtest-visualization-888from
feat/webview-ipc-refactor

Conversation

@EhabY
Copy link
Copy Markdown
Collaborator

@EhabY EhabY commented Apr 20, 2026

  • Extract shared extension-side dispatch helpers (isIpcCommand, isIpcRequest, notifyWebview, dispatchCommand, dispatchRequest, onWhileVisible) into src/webviews/util.ts. tasksPanelProvider / speedtestPanel / chatPanelProvider all migrate to them.
  • Add vanilla webview-side helpers sendCommand / onNotification in @repo/webview-shared for non-React webviews (speedtest uses them; React webviews keep useIpc).
  • Every panel now calls both buildCommandHandlers and buildRequestHandlers (empty {} is fine): any new defineCommand / defineRequest on an Api produces a compile error at the panel missing a handler, so the extension can't silently drop a future action.
  • Document the contract once in packages/webview-shared/README.md. CONTRIBUTING.md and AGENTS.md point at it as the single source of truth.
  • Chat panel was speaking an ad-hoc {type, ...} protocol; it now uses ChatApi + shared dispatchers. The iframe shim still speaks the Coder server's {type, payload} contract, but the shim-to-extension side is IPC. The shim was split into toIframe / handleFromIframe / handleFromExtension / showRetry so dispatch reads straight through.

@EhabY EhabY force-pushed the feat/speedtest-visualization-888 branch from 781bd7a to 8c6204a Compare April 20, 2026 15:20
@EhabY EhabY force-pushed the feat/webview-ipc-refactor branch from df4afc3 to abfbedc Compare April 20, 2026 18:06
@EhabY EhabY force-pushed the feat/speedtest-visualization-888 branch 2 times, most recently from 4e7be71 to 973e57a Compare April 21, 2026 13:13
@EhabY EhabY force-pushed the feat/webview-ipc-refactor branch from abfbedc to f890b00 Compare April 21, 2026 13:28
@EhabY EhabY force-pushed the feat/speedtest-visualization-888 branch from 973e57a to 83a1ca1 Compare April 21, 2026 13:50
@EhabY EhabY force-pushed the feat/webview-ipc-refactor branch from f890b00 to 30594e4 Compare April 21, 2026 13:50
@EhabY EhabY force-pushed the feat/speedtest-visualization-888 branch from 83a1ca1 to 1ce0401 Compare April 21, 2026 14:22
EhabY added 2 commits April 21, 2026 17:22
…ness

- Add isIpcCommand/Request, notifyWebview, dispatchCommand/Request, and
  onWhileVisible in src/webviews/util.ts; migrate tasksPanelProvider and
  speedtestPanel off their local copies.
- Add sendCommand/onNotification in @repo/webview-shared for vanilla
  webviews; useIpc stays for React.
- speedtestPanel calls buildCommandHandlers AND buildRequestHandlers,
  so adding a new action to SpeedtestApi is a compile error until a
  handler is wired.
- Document the contract and the visibility/theme re-send guarantee in
  packages/webview-shared/README.md; AGENTS.md and CONTRIBUTING.md
  point at it.
- Expand speedtestPanel tests (payload, visibility/theme re-send,
  viewJson dispatch, cleanup) and add ipc.test.ts for the new helpers.
Define ChatApi in shared and replace the ad-hoc {type, ...} message
handling with buildCommandHandlers / buildRequestHandlers plus
dispatchCommand / dispatchRequest. Outgoing notifications route
through a private notify() wrapper, mirroring tasksPanelProvider.

The iframe shim in the inline HTML keeps its own {type, payload}
contract with the Coder server, but its shim-to-extension side now
speaks the IPC wire format. Split the handler into handleFromIframe /
handleFromExtension + a toIframe helper + a showRetry builder so the
dispatch reads straight through.

Tests updated to the new wire format.
@EhabY EhabY force-pushed the feat/webview-ipc-refactor branch from 30594e4 to 6647e51 Compare April 21, 2026 14:22
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