Skip to content

Commit

Permalink
feat(trpc): use fetch fn that directs to window.fetch
Browse files Browse the repository at this point in the history
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()`.
  • Loading branch information
LoneRifle authored Nov 22, 2023
1 parent d23fb70 commit cf3ff77
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/utils/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf3ff77

Please sign in to comment.