Upgrading from 0.x
electron-trpc 1.0 supports tRPC 11 and Electron 35 or later. The 0.x releases, which support tRPC 10, are no longer maintained.
Dependencies
Section titled “Dependencies”Update electron-trpc, tRPC and Electron together:
pnpm add electron-trpc@^1 @trpc/server@^11 @trpc/client@^11pnpm add -D electron@latesttRPC 11 has its own breaking changes. Follow tRPC’s migration guide for your router and client code.
Main process
Section titled “Main process”createIPCHandler answers requests from any window and cleans up after each one, so it no longer takes a windows option, and attachWindow and detachWindow are gone.
It also registers electron-trpc’s preload script, so create it before your windows load their pages:
app.on('ready', () => { createIPCHandler({ router });
const win = new BrowserWindow({ webPreferences: { preload: path.join(__dirname, 'preload.js'), }, }); createIPCHandler({ router, windows: [win] }); const win = new BrowserWindow();});Preload script
Section titled “Preload script”electron-trpc now brings its own preload script, so what to do with yours depends on what else it does:
- It only exposed electron-trpc: delete it, along with its build entry and
webPreferences.preload. - It also exposes your own APIs: remove
exposeElectronTRPCfrom it. electron-trpc’s preload script runs alongside it. - You want to keep exposing electron-trpc yourself: pass
preload: falsetocreateIPCHandler, and importexposeElectronTRPCfromelectron-trpc/preloadinstead ofelectron-trpc/main.
Renderer
Section titled “Renderer”In tRPC 11, data transformers move from the client to its links, so pass yours to ipcLink:
const client = createTRPCClient<AppRouter>({ transformer: superjson, links: [ipcLink()], links: [ipcLink({ transformer: superjson })],});tRPC 11 also renames createTRPCProxyClient to createTRPCClient, though the old name still works. For React, @trpc/react-query still works with tRPC 11, and tRPC now also offers a TanStack React Query integration.
Subscriptions
Section titled “Subscriptions”Observable subscriptions still work, but tRPC 11 recommends async generators, which end through the signal tRPC passes them. Subscriptions also end in more situations than before, such as when their page reloads or their iframe is removed. See Request lifetimes.
New in 1.0
Section titled “New in 1.0”- An
allowoption to reject requests by sender. preload: { sessions }to register the preload script on sessions other than the default.- A
Disposablehandler, which ends every request still running when disposed. - Pages with several tRPC clients get the right responses, and electron-trpc works in sandboxed renderers.