Adopt the published @microsoft/vscode-ext-webview, retire the local @cosmosdb/webview-rpc - #3217
Adopt the published @microsoft/vscode-ext-webview, retire the local @cosmosdb/webview-rpc#3217Tomasz Naumowicz (tnaum-ms) wants to merge 5 commits into
Conversation
Adds the published webview transport package and its required @trpc/client and @trpc/server peer dependencies ahead of migrating off the local @cosmosdb/webview-rpc workspace package.
…-webview
Repoints all src/panels/** transport code from the local
@cosmosdb/webview-rpc workspace package to the published
@microsoft/vscode-ext-webview package:
- trpc.ts: initTRPC.context().create() -> initWebviewTrpc(); the logging
body is now wired per-invocation (loggingMiddlewareBody(opts, logger))
and the curried telemetry body is applied directly.
- setupTrpc() -> attachTrpc() in the four panel tabs.
- azextTelemetryRunner: reads cancellation via getInvocationSignal(ctx).
- BaseRouterContext / TypedEventSink / ProcedureLogger now come from the
package.
No behavior change: the runner still injects { actionContext } and
procedures keep reading ctx.actionContext.
Repoints all webview React code from @cosmosdb/webview-rpc/react to
@microsoft/vscode-ext-webview/react and adopts the 0.10.0 hook split:
- useTrpcClient() now returns the tRPC client directly instead of a
{ trpcClient, events } tuple.
- Views that observe webview-wide RPC outcomes (Document, Query Editor)
read the event channel from the new useRpcEvents() hook.
- WithWebviewContext / WebviewState / TrpcClient / AnyRouter now come from
the package.
- GenerateQueryInput test mock updated to the new hook contract.
The extension now consumes the published @microsoft/vscode-ext-webview package everywhere, so the local workspace package is no longer needed. - Deletes packages/webview-rpc and its packages/README.md entry. - Removes the @cosmosdb/webview-rpc path aliases from tsconfig.base.json, vite.config.ext.mjs, vite.config.views.mjs, and vitest.config.ts. - Updates docs/trpc-webview-guide.md to reference attachTrpc and the package import paths. - Refreshes package-lock.json.
@microsoft/vscode-ext-webview ships CommonJS. List its dev-facing subpaths in optimizeDeps.include so Vite pre-bundles the CJS->ESM interop shim at dev-server start, instead of triggering a re-optimize and a full webview reload the first time a panel opens. Dev-only and removable once the package ships an ESM build.
✅ Build (Compile, Lint, Prettier, l10n, Package)🧱 Step Results
📥 Artifacts (run) |
Full story: what was done and whyBackgroundThe webview tRPC transport in this extension (the postMessage wire protocol, the abort-aware host dispatcher, the client links, Part of that shared work was making the published package flexible enough for the more advanced, all-in-one scenarios this extension relies on, not only the simple case:
The one contract that made this possibleEarlier package versions exposed only a minimal telemetry bag on the context. This extension needs the full Commit by commit
One type-safety fix worth calling outThe new Validation
Risk and suggested smoke testLow. The runner still injects |
There was a problem hiding this comment.
Pull request overview
Migrates the extension and its webviews from the in-repo @cosmosdb/webview-rpc workspace package to the published @microsoft/vscode-ext-webview package, then removes the local transport package and its related build/test path aliases.
Changes:
- Swap tRPC/webview transport imports and host wiring to
@microsoft/vscode-ext-webview(includingattachTrpc,initWebviewTrpc,useTrpcClient, anduseRpcEvents). - Remove
packages/webview-rpcand delete corresponding TS/Vite/Vitest aliases. - Update build tooling/deps (Vite
optimizeDeps.include, root dependencies) and refresh tRPC webview documentation.
Reviewed changes
Copilot reviewed 57 out of 58 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| vitest.config.ts | Removes @cosmosdb/webview-rpc test-time path aliases. |
| vite.config.views.mjs | Pre-bundles @microsoft/vscode-ext-webview subpaths; removes @cosmosdb/webview-rpc aliases. |
| vite.config.ext.mjs | Removes @cosmosdb/webview-rpc extension-bundle aliases. |
| tsconfig.base.json | Removes @cosmosdb/webview-rpc* path mappings. |
| src/webviews/utils/context/BaseContextProvider.tsx | Switches React-layer tRPC client types to @microsoft/vscode-ext-webview/react. |
| src/webviews/index.tsx | Switches WithWebviewContext/WebviewState import to @microsoft/vscode-ext-webview/react. |
| src/webviews/cosmosdb/QueryEditor/state/QueryEditorContextProvider.tsx | Switches TrpcClient type import to @microsoft/vscode-ext-webview/react. |
| src/webviews/cosmosdb/QueryEditor/state/QueryEditorContext.tsx | Adopts useTrpcClient() + useRpcEvents() hook split. |
| src/webviews/cosmosdb/QueryEditor/quickStart/QuickStartProvider.tsx | Updates useTrpcClient() usage to new return type (client only). |
| src/webviews/cosmosdb/QueryEditor/QueryPanel/GenerateQueryInput.tsx | Updates useTrpcClient() usage to new return type (client only). |
| src/webviews/cosmosdb/QueryEditor/QueryPanel/GenerateQueryInput.test.tsx | Updates mocks to match new useTrpcClient()/useRpcEvents() contract. |
| src/webviews/cosmosdb/Migration/state/MigrationChannel.ts | Switches TrpcClient type import to @microsoft/vscode-ext-webview/react. |
| src/webviews/cosmosdb/Migration/MigrationAssistant.tsx | Updates useTrpcClient() usage to new return type (client only). |
| src/webviews/cosmosdb/Document/state/DocumentContextProvider.tsx | Switches TrpcClient type import to @microsoft/vscode-ext-webview/react. |
| src/webviews/cosmosdb/Document/state/DocumentContext.tsx | Adopts useTrpcClient() + useRpcEvents() hook split. |
| src/webviews/cosmosdb/AccountOverview/AccountOverview.tsx | Updates useTrpcClient() usage to new return type (client only). |
| src/panels/trpc/trpc.ts | Moves server-side tRPC initialization and middleware bodies to @microsoft/vscode-ext-webview / host. |
| src/panels/trpc/routers/queryEditorEventsRouter.ts | Switches TypedEventSink import to @microsoft/vscode-ext-webview. |
| src/panels/trpc/routers/migrationEventsRouter.ts | Switches TypedEventSink import to @microsoft/vscode-ext-webview. |
| src/panels/trpc/middleware/outputChannelLogger.ts | Switches ProcedureLogger type import to @microsoft/vscode-ext-webview/host. |
| src/panels/trpc/middleware/azextTelemetryRunner.ts | Updates telemetry runner to new host types/APIs (e.g., getInvocationSignal). |
| src/panels/trpc/appRouter.ts | Switches base context + event sink imports to @microsoft/vscode-ext-webview. |
| src/panels/QueryEditorTab.ts | Replaces setupTrpc with attachTrpc from @microsoft/vscode-ext-webview/host. |
| src/panels/MigrationAssistantTab.ts | Replaces setupTrpc with attachTrpc from @microsoft/vscode-ext-webview/host. |
| src/panels/migration/steps/phase4Provisioning.ts | Switches TypedEventSink type import to @microsoft/vscode-ext-webview. |
| src/panels/migration/steps/phase3SchemaConversion.ts | Switches TypedEventSink type import to @microsoft/vscode-ext-webview. |
| src/panels/migration/steps/phase2Assessment.ts | Switches TypedEventSink type import to @microsoft/vscode-ext-webview. |
| src/panels/migration/steps/phase1Discovery.ts | Switches TypedEventSink type import to @microsoft/vscode-ext-webview. |
| src/panels/migration/helpers/migrationHelpers.ts | Switches TypedEventSink type import to @microsoft/vscode-ext-webview. |
| src/panels/DocumentTab.ts | Replaces setupTrpc with attachTrpc from @microsoft/vscode-ext-webview/host. |
| src/panels/AccountOverviewTab.ts | Replaces setupTrpc with attachTrpc from @microsoft/vscode-ext-webview/host. |
| packages/webview-rpc/tsconfig.json | Removes local transport package config (package retirement). |
| packages/webview-rpc/src/shared/vscodeProtocol.ts | Removes local transport shared protocol types (package retirement). |
| packages/webview-rpc/src/shared/TypedEventSink.ts | Removes local TypedEventSink implementation (package retirement). |
| packages/webview-rpc/src/shared/TypedEventSink.test.ts | Removes local TypedEventSink tests (package retirement). |
| packages/webview-rpc/src/server/setupTrpc.ts | Removes local host-side setupTrpc implementation (package retirement). |
| packages/webview-rpc/src/server/middleware/types.ts | Removes local middleware shared types (package retirement). |
| packages/webview-rpc/src/server/middleware/telemetryMiddleware.ts | Removes local telemetry middleware body (package retirement). |
| packages/webview-rpc/src/server/middleware/loggingMiddleware.ts | Removes local logging middleware body (package retirement). |
| packages/webview-rpc/src/server/middleware/index.ts | Removes local middleware barrel export (package retirement). |
| packages/webview-rpc/src/server/index.ts | Removes local server-side entrypoint (package retirement). |
| packages/webview-rpc/src/server/baseRouterContext.ts | Removes local base router context types (package retirement). |
| packages/webview-rpc/src/react/WebviewContext.tsx | Removes local React provider (package retirement). |
| packages/webview-rpc/src/react/useTrpcClient.ts | Removes local React hook implementation (package retirement). |
| packages/webview-rpc/src/react/index.ts | Removes local React subpath barrel (package retirement). |
| packages/webview-rpc/src/index.ts | Removes local package root barrel (package retirement). |
| packages/webview-rpc/src/client/vscodeLink.ts | Removes local client-side transport link (package retirement). |
| packages/webview-rpc/src/client/vscodeLink.test.ts | Removes local client-side transport tests (package retirement). |
| packages/webview-rpc/src/client/index.ts | Removes local client-side entrypoint (package retirement). |
| packages/webview-rpc/src/client/events.ts | Removes local client-side events channel (package retirement). |
| packages/webview-rpc/src/client/errorLink.ts | Removes local client-side errorLink (package retirement). |
| packages/webview-rpc/src/client/errorLink.test.ts | Removes local client-side errorLink tests (package retirement). |
| packages/webview-rpc/README.md | Removes local package documentation (package retirement). |
| packages/webview-rpc/package.json | Removes local package manifest (package retirement). |
| packages/README.md | Removes @cosmosdb/webview-rpc from active packages list. |
| package.json | Adds @microsoft/vscode-ext-webview and required @trpc/* deps. |
| package-lock.json | Locks new dependencies and removes workspace link for the retired package. |
| docs/trpc-webview-guide.md | Updates guide to reference attachTrpc and new package imports. |
Code Coverage OverviewLanguages: TypeScript TypeScript / code-coverage/vitestThe overall coverage in commit 620206e in the Show a code coverage summary of the most impacted files.
|
🧪 Tests (Unit + Integration)🧪 Results
📈 Coverage |
🎭 E2E Tests (Playwright + VS Code)🧪 Result
📥 Artifacts (run)
|
Adopt the published
@microsoft/vscode-ext-webview, retire the local@cosmosdb/webview-rpcSwaps the in-repo
packages/webview-rpcworkspace package for the published@microsoft/vscode-ext-webview(~0.10.0) across the extension, then removes the local package. This is a transport-layer swap with no user-facing behavior change. The actual code changes are small and mostly mechanical: updated import paths plus a few call-site renames (27 source files, about +90/-85 lines). The bulk of the diff is just removing the local package.Why
The local
@cosmosdb/webview-rpcand the published@microsoft/vscode-ext-webviewshare the same roots: both grew from the same webview tRPC transport. Since then the published package has gained the flexibility that advanced, all-in-one consumers like this extension need: a generic telemetry runner that carries the fullIActionContexton the procedure context, a hostattachTrpcprimitive that fits the panel model yourBaseTabalready uses, and auseTrpcClient()/useRpcEvents()hook split. Now we can bring the two back together again :)Commits
build: add @microsoft/vscode-ext-webview and @trpc peer depsadds the package and its required@trpc/clientand@trpc/server ~11.18.0peers.refactor(trpc): migrate extension-host layermoves all ofsrc/panels/**to the package:initWebviewTrpc,attachTrpc, the package middleware bodies, and cancellation viagetInvocationSignal.refactor(webviews): migrate React layermoves all webview code to/react, souseTrpcClient()returns the client anduseRpcEvents()supplies the event channel, and updates theGenerateQueryInputtest mock.chore: remove local @cosmosdb/webview-rpc packagedeletespackages/webview-rpc, its path aliases (tsconfig, both vite configs, vitest), itspackages/README.mdrow, and refreshesdocs/trpc-webview-guide.md.build(views): pre-bundle @microsoft/vscode-ext-webview subpaths in devlists the package's dev-facing subpaths inoptimizeDeps.includeso Vite pre-bundles the still-CommonJS package at dev-server start, avoiding a re-optimize and reload on first webview open. Dev-only, removable once the package ships ESM.One work item per commit, for easy review.
Please smoke-test
I verified the four webviews open and work, but you know this extension far better than I do. Please give it a pass to confirm behavior matches pre-migration, especially Query Editor, Document, Migration Assistant, and Account Overview, including live subscriptions and events, cancellation (Stop), and error surfacing. Flag anything that feels different.
Local dev note
The webview dev server uses port 18080, which collides with vscode-documentdb's dev server. If you run both, only one can own the port; see #3216. This does not affect the shipped code in this PR.