Skip to content

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.

Update electron-trpc, tRPC and Electron together:

Terminal window
pnpm add electron-trpc@^1 @trpc/server@^11 @trpc/client@^11
pnpm add -D electron@latest

tRPC 11 has its own breaking changes. Follow tRPC’s migration guide for your router and client code.

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:

main.ts
app.on('ready', () => {
createIPCHandler({ router });
const win = new BrowserWindow({
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
},
});
createIPCHandler({ router, windows: [win] });
const win = new BrowserWindow();
});

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 exposeElectronTRPC from it. electron-trpc’s preload script runs alongside it.
  • You want to keep exposing electron-trpc yourself: pass preload: false to createIPCHandler, and import exposeElectronTRPC from electron-trpc/preload instead of electron-trpc/main.

In tRPC 11, data transformers move from the client to its links, so pass yours to ipcLink:

renderer.ts
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.

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.

  • An allow option to reject requests by sender.
  • preload: { sessions } to register the preload script on sessions other than the default.
  • A Disposable handler, which ends every request still running when disposed.
  • Pages with several tRPC clients get the right responses, and electron-trpc works in sandboxed renderers.