diff --git a/apps/dashboard/src/lib/trpc/shared.ts b/apps/dashboard/src/lib/trpc/shared.ts index 110c9eb5..01f8f361 100644 --- a/apps/dashboard/src/lib/trpc/shared.ts +++ b/apps/dashboard/src/lib/trpc/shared.ts @@ -1,7 +1,7 @@ import type { AppRouter } from "@openstatus/api"; import * as Sentry from "@sentry/nextjs"; -import type { HTTPBatchLinkOptions, HTTPHeaders, TRPCLink } from "@trpc/client"; -import { httpBatchLink, loggerLink } from "@trpc/client"; +import type { HTTPHeaders, TRPCLink } from "@trpc/client"; +import { httpBatchStreamLink, loggerLink } from "@trpc/client"; import superjson from "superjson"; /** @@ -56,16 +56,19 @@ const getBaseUrl = () => { // The whole tRPC surface is served from a single Node.js endpoint — there is // no longer an Edge/Node split, so all calls go to one link. +// Streaming rather than plain batching: a batch mixing cheap queries with a +// slow Tinybird pipe would otherwise deliver none of them until the slowest +// one settles. Note this makes per-procedure errors arrive in-band on a 200 — +// `sentryLoggerLink` above is what still reports them. export const endingLink = (opts?: { fetch?: typeof fetch; headers?: HTTPHeaders | (() => HTTPHeaders | Promise); }): TRPCLink => (runtime) => - httpBatchLink({ + httpBatchStreamLink({ headers: opts?.headers, fetch: opts?.fetch, transformer: superjson, url: `${getBaseUrl()}/api/trpc/lambda`, - // oxlint-disable-next-line typescript/no-explicit-any -- FIXME: remove any - } satisfies Partial>)(runtime); + })(runtime);