tRPC v11.36.0, released on 2 December 2026, adds one focused feature for real-time Node.js backends: per-subscription SSE options. Before this, every subscription served over server-sent events shared one set of settings for ping interval, client reconnect timeout and maximum duration. Now the server can choose them for each subscription, based on the procedure path, the request context and the procedure’s metadata.
This guide explains why that matters, shows a working setup with @trpc/[email protected] on Node’s standalone adapter, and covers the edge cases we ran into. The code was run against the real package, and the output shown is from that run.
Why per-subscription options?
The pull request that added the feature, trpc/trpc#8245, gives the reason plainly: “A busy subscription may need frequent pings, while a quiet one can go minutes between them. Today they share one timer configuration.”
Some real examples:
- A live price ticker wants frequent pings and a short client reconnect timeout, so a dead connection is noticed within seconds.
- An audit log stream might go minutes between events. It can ping rarely and should have a maximum duration so connections are recycled.
- An old subscription you want to turn off for SSE without touching the others.
Install
npm i @trpc/[email protected] @trpc/[email protected]
The new option: sse can be a function
In 11.36 the sse root option takes either the existing options object or a function. From the package’s type definitions:
sse?: SSEConfig | ((opts: {
path: string;
ctx: TTypes['ctx'];
meta: TTypes['meta'] | undefined;
}) => SSEConfig | undefined);
SSEConfig contains the fields you already know:
enabled(defaulttrue): whether subscriptions can be served over SSEping: { enabled, intervalMs }: server keep-alive pings. Pings are off by default, and the default interval is 1000 ms.client: { reconnectAfterInactivityMs }: sent to the client in the first messagemaxDurationMs: ends the stream after this longemitAndEndImmediately: for serverless runtimes that can’t stream
Return undefined to use the defaults. The type comments describe exactly that.
A working example
Here’s a server with three subscriptions that each get different SSE behaviour. It uses procedure metadata (.meta()) to tag subscriptions and the path for one special case:
// server.mjs
import { initTRPC } from '@trpc/server';
import { createHTTPServer } from '@trpc/server/adapters/standalone';
const t = initTRPC
.context()
.meta()
.create({
sse: ({ path, meta }) => {
if (meta?.sse === 'disabled') return { enabled: false };
if (path === 'ticker.live') {
return {
ping: { enabled: true, intervalMs: 500 },
client: { reconnectAfterInactivityMs: 2_000 },
};
}
if (meta?.sse === 'quiet') {
return { ping: { enabled: true, intervalMs: 3_000 }, maxDurationMs: 60_000 };
}
return undefined; // defaults
},
});
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
export const appRouter = t.router({
ticker: t.router({
live: t.procedure.subscription(async function* () {
for (let i = 0; i < 2; i++) { await sleep(1200); yield { tick: i }; }
}),
}),
audit: t.procedure.meta({ sse: 'quiet' }).subscription(async function* () {
await sleep(1200); yield { event: 'login' };
}),
legacy: t.procedure.meta({ sse: 'disabled' }).subscription(async function* () {
yield 1;
}),
});
createHTTPServer({ router: appRouter }).listen(3123);
In TypeScript you’d type the metadata with .meta<{ sse?: 'quiet' | 'disabled' }>(). Then the meta argument in the selector is fully typed.
What actually goes over the wire
We ran the server on Node.js and read each stream with fetch(). You can do the same with curl:
curl -N -H "accept: text/event-stream" http://localhost:3123/ticker.live
ticker.live: the first event carries the client options, and ping events arrive every 500 ms before the first tick:
event: connected
data: {"reconnectAfterInactivityMs":2000}
event: ping
data:
event: ping
data:
data: {"tick":0}
audit: the 3-second ping interval means no pings appeared before the single event, and the client got no reconnect settings:
event: connected
data: {}
data: {"event":"login"}
event: return
legacy: with enabled: false, the stream opened and then sent a serialized-error with code METHOD_NOT_SUPPORTED (HTTP status 405 in the error data). The other subscriptions weren’t affected.
So the selector really does apply different settings to different streams from the same server.
Choosing options from the request context
Because the selector also gets ctx, you can tune SSE per user or per tenant. For example, mobile clients might get a longer reconnect timeout:
const t = initTRPC
.context<{ isMobile: boolean }>()
.meta<{ sse?: 'quiet' }>()
.create({
sse: ({ ctx, meta }) => ({
ping: { enabled: true, intervalMs: meta?.sse === 'quiet' ? 15_000 : 2_000 },
client: { reconnectAfterInactivityMs: ctx.isMobile ? 20_000 : 6_000 },
}),
});
A good rule of thumb is to keep reconnectAfterInactivityMs comfortably larger than the ping interval. Otherwise clients will reconnect even though the server is healthy and just quiet.
Edge cases to know
- Returning
undefineduses tRPC’s defaults (pings off), exactly as if you hadn’t setsse. - If your selector throws, the PR says the client gets the error streamed using the default connection settings. Keep the selector simple and synchronous.
- The old style still works. Passing a plain object to
ssebehaves as before, so upgrading is safe. - Proxies and load balancers may close idle connections. Pings are what keep long, quiet streams alive through them, so don’t turn pings off on quiet subscriptions behind a proxy.
Client side
Nothing changes on the client for this feature. httpSubscriptionLink reads the reconnectAfterInactivityMs value the server sends in the connected event. The tRPC docs cover SSE options on the server and client setup. The PR notes there’s related ongoing work on a fetch-based httpSSELink, which is worth watching if you want to drop the EventSource dependency.
Takeaway
tRPC 11.36 lets one Node.js server handle very different real-time streams sensibly: frequent pings for busy feeds, rare pings and recycling for quiet ones, and a per-procedure off switch. It’s a small, backwards-compatible change. Upgrade, tag your subscriptions with metadata, and move your SSE settings into one selector function. The v11.36.0 release has the details.
