microsoft/vscode-documentdb/webview-trpc-messaging
Claude Code and agent skill by microsoft/vscode-documentdb
- community
- verified
Checking that the SKILL.md file is still in the repository.
Implements tRPC-based communication between VS Code extension host and React webviews. Use when creating new webview procedures (queries, mutations, subscriptions), adding a new webview router, wiring up a webview controller, using the tRPC client from React components, applying telemetry middleware (telemetryMiddlewareBody), or supporting AbortSignal-based cancellation in webview operations.
Install
npx vskill@latest install microsoft/vscode-documentdb/webview-trpc-messagingSKILL.md
Webview tRPC Messaging
Type-safe RPC communication between the VS Code extension host (server) and React webviews (client) using tRPC.
Architecture Overview
Key files (read as needed for implementation details):
| File | Purpose | |
|---|---|---|
@microsoft/vscode-ext-webview (shared) | tRPC init via initWebviewTrpc, publicProcedure, router, BaseRouterContext | |
@microsoft/vscode-ext-webview/host (telemetry) | telemetryMiddlewareBody, ProcedureLogger, TelemetryRunner (consumer builds publicProcedureWithTelemetry) | |
src/webviews/_integration/trpc.ts | Consumer tRPC instance: publicProcedureWithTelemetry, the DocumentDB TelemetryRunner, and the RpcEnrichment shape it contributes to ctx.actionContext | |
src/webviews/_integration/appRouter.ts | Root router + publicProcedureWithTelemetry wiring + DocumentDB BaseRouterContext | |
src/webviews/_integration/configuration.ts | Consumer-owned knobs (telemetry namespace, bundle layout, dev-server host) | |
@microsoft/vscode-ext-webview/host (WebviewController) | WebviewController + openWebview factory: WebviewPanel lifecycle, tRPC dispatcher (queries, mutations, subscriptions, abort) | |
src/webviews/_integration/openAppWebview.ts | DocumentDB factory preset that pre-fills router + bundle layout (openAppWebview) | |
src/webviews/_integration/useTrpcClient.ts | React hook providing the tRPC client (pre-typed against AppRouter) | |
@microsoft/vscode-ext-webview/webview (vscodeLink) | Custom tRPC link bridging postMessage transport |
Creating a New Router
Each webview maintains its own router. Follow this pattern:
1. Define the router context
Extend BaseRouterContext with view-specific fields:
2. Define procedures
3. Register in appRouter
4. Create the controller
Construction-only panels are opened with a factory function that builds the config + router context and calls the openAppWebview preset (which pre-fills the app router, caller factory, and bundle layout):
The returned AppWebviewController handle exposes panel, onDisposed, revealToForeground, isDisposed, and dispose. Genuinely stateful panels may still extend WebviewController from @microsoft/vscode-ext-webview/host directly instead of using the factory.
Important: ThewebviewNamefield passed toopenAppWebviewis theregistry key (viewType, must match a key inWebviewRegistry, e.g.collectionView). ThewebviewNamein the tRPC context is a **telemetrylabel** used in telemetry event names. These may be the same string but servedifferent purposes -- do not confuse them.
5. Register in WebviewRegistry
Add your React component to the registry. The key must match the webviewName passed to openAppWebview (viewType). The WebviewName type (exported from the same file) ensures compile-time validation of webview names.
Telemetry: publicProcedure vs publicProcedureWithTelemetry
| Base | When to use | ctx.actionContext | |
|---|---|---|---|
publicProcedure | Fire-and-forget, no external calls, telemetry reported separately | absent (do not read it) | |
publicProcedureWithTelemetry | Default choice. Any procedure touching DB, network, or user-visible work | Guaranteed, injected by the DocumentDB TelemetryRunner |
publicProcedureWithTelemetry is publicProcedure.use(telemetryMiddlewareBody(documentDbTelemetryRunner, ...)) (built in trpc.ts). The framework's telemetryMiddlewareBody delegates to the DocumentDB TelemetryRunner, which wraps the call in callWithTelemetryAndErrorHandling, contributes the full IActionContext to ctx.actionContext, auto-generates a telemetry event named documentDB.rpc.{type}.{path}, and records errors, duration, and abort status.
actionContext is not a field on the base RouterContext — it is an additive enrichment. Narrow to WithTelemetry<RouterContext> (= RouterContext & { actionContext }) in an instrumented procedure to read it; a plain publicProcedure procedure narrows to bare RouterContext, so reading actionContext there is a compile error instead of a runtime undefined.
Access telemetry safely:
AbortSignal Support
Every tRPC operation (query, mutation, subscription) receives its own AbortController. Cancellation flows:
Using abort in procedures
Client-side abort
When publicProcedureWithTelemetry detects an aborted signal, the DocumentDB TelemetryRunner sets telemetry.properties.aborted = 'true' and result = 'Canceled' automatically.
Subscriptions
Subscriptions stream multiple values from server to client using async generators:
Client-Side Hook Usage
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files. Certified 10 Mar 2026.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryChecking.github/skills/webview-trpc-messaging/SKILL.md
Popularity
- Repository stars
- 21
- Repository forks
- 8
- 7-day trend score
- 15
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 17 Mar 2026, 8 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/microsoft/vscode-documentdb/webview-trpc-messaging)