tRPC subscriptions throw a net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK) error when using an httpSubscriptionLink that uses Server-sent Events (SSE) for subscriptions
This causes the client to continuously fire off new subscription calls.
This seems restricted to subscriptions so far as mutations and queries seem fine.
server.ts:
import { initTRPC } from '@trpc/server'
import { cors } from 'hono/cors'
import { trpcServer } from '@hono/trpc-server'
import { z } from 'zod'
import { EventEmitter, on } from 'events'
import { randomUUID } from 'crypto'
import superjson from 'superjson'
import { Hono } from 'hono'
import { EVENT, Widget } from '../common'
const t = initTRPC.create({
transformer: superjson
})
const eventEmitter = new EventEmitter()
const publicProcedure = t.procedure
const router = t.router
const appRouter = router({
create: publicProcedure
.input(
z.object({
name: z.string()
})
)
.mutation(({ input }) => {
const widget: Widget = {
...input,
id: randomUUID(),
createdAt: new Date().toDateString()
} satisfies Widget
eventEmitter.emit(EVENT.CREATE, widget)
}),
onCreate: publicProcedure.subscription(async function* (opts) {
for await (const [data] of on(eventEmitter, EVENT.CREATE)) {
const widget = data as Widget
yield widget
}
})
})
export type AppRouter = typeof appRouter
const app = new Hono().use(cors()).use(
'*',
trpcServer({
router: appRouter
})
)
export default {
port: 3001,
fetch: app.fetch
}
tRPC subscriptions throw a
net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK)
error when using anhttpSubscriptionLink
that uses Server-sent Events (SSE) for subscriptionsThis causes the client to continuously fire off new subscription calls.
This seems restricted to subscriptions so far as mutations and queries seem fine.
server.ts
:client:
trpc.ts
App.tsx
Running the same code using node HTTP server seems fine: