From cf3ff77335116499d38121be082bbb8e7c97b3a4 Mon Sep 17 00:00:00 2001 From: LoneRifle Date: Wed, 22 Nov 2023 17:20:29 +0800 Subject: [PATCH] feat(trpc): use fetch fn that directs to window.fetch By default, tRPC will retain its own reference to window.fetch on init. Any changes to or replacements of window.fetch would not be picked up by tRPC, which will affect eg, instrumentation by Datadog RUM. Fix this by supplying our own fetch implementation that delegates to whatever is the current global `fetch()`. --- src/utils/trpc.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/utils/trpc.ts b/src/utils/trpc.ts index dd1cd8e9..ec42dd73 100644 --- a/src/utils/trpc.ts +++ b/src/utils/trpc.ts @@ -110,6 +110,14 @@ export const trpc = createTRPCNext< }), httpBatchLink({ url: `${getBaseUrl()}/api/trpc`, + /** + * Provide a function that will invoke the current global + * window.fetch. We do this to pick up any changes to fetch + * at runtime, eg, by Datadog RUM + */ + fetch(url, options) { + return fetch(url, options) + }, /** * Set custom request headers on every request from tRPC * @link https://trpc.io/docs/ssr