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' }), }), ], });