Skip to content

Open-source status page, incident response and uptime monitoring

perf: stream the dashboard tRPC batch response (#2549)

Thibault Le Ouay37c2238624b1
diff --git a/apps/dashboard/src/lib/trpc/shared.ts b/apps/dashboard/src/lib/trpc/shared.ts
index 110c9eb5b..01f8f3616 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<HTTPHeaders>);
}): TRPCLink<AppRouter> =>
(runtime) =>
- httpBatchLink({
+ httpBatchStreamLink<AppRouter>({
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<HTTPBatchLinkOptions<any>>)(runtime);
+ })(runtime);