From eaf3f107228ec86636eac80383915ee060fbd9ab Mon Sep 17 00:00:00 2001 From: Lukas May Date: Wed, 4 Feb 2026 22:20:16 +0100 Subject: [PATCH] feat(20-02): add splitLink to route subscriptions to SSE httpSubscriptionLink MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace single httpBatchLink with splitLink that routes subscription operations to httpSubscriptionLink (SSE) while keeping queries/mutations on httpBatchLink. No new packages needed — both exports are part of @trpc/client v11. --- packages/web/src/lib/trpc.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/web/src/lib/trpc.ts b/packages/web/src/lib/trpc.ts index 1da1a55..d0a6fd5 100644 --- a/packages/web/src/lib/trpc.ts +++ b/packages/web/src/lib/trpc.ts @@ -1,5 +1,5 @@ import { createTRPCReact } from '@trpc/react-query'; -import { httpBatchLink } from '@trpc/client'; +import { httpBatchLink, splitLink, httpSubscriptionLink } from '@trpc/client'; import type { AppRouter } from '@codewalk-district/shared'; export const trpc = createTRPCReact(); @@ -7,10 +7,10 @@ export const trpc = createTRPCReact(); export function createTRPCClient() { return trpc.createClient({ links: [ - httpBatchLink({ - // In dev, Vite proxy forwards /trpc to backend - // In prod, same-origin or configured URL - url: '/trpc', + splitLink({ + condition: (op) => op.type === 'subscription', + true: httpSubscriptionLink({ url: '/trpc' }), + false: httpBatchLink({ url: '/trpc' }), }), ], });