feat(20-02): add splitLink to route subscriptions to SSE httpSubscriptionLink

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.
This commit is contained in:
Lukas May
2026-02-04 22:20:16 +01:00
parent 8cfdfe987b
commit eaf3f10722

View File

@@ -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<AppRouter>();
@@ -7,10 +7,10 @@ export const trpc = createTRPCReact<AppRouter>();
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' }),
}),
],
});