Skip to content

Commit d12fc11

Browse files
committed
fix: replace makeQueryClient with cached getQueryClient for consistent query client behavior across requests
1 parent 957d50c commit d12fc11

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

app/[domain]/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { DomainReportView } from "@/components/domain/domain-report-view";
55
import { analytics } from "@/lib/analytics/server";
66
import { normalizeDomainInput } from "@/lib/domain";
77
import { toRegistrableDomain } from "@/lib/domain-server";
8-
import { makeQueryClient } from "@/trpc/query-client";
9-
import { trpc } from "@/trpc/server";
8+
import { getQueryClient, trpc } from "@/trpc/server";
109

1110
import "country-flag-icons/3x2/flags.css";
1211
import "mapbox-gl/dist/mapbox-gl.css";
@@ -52,7 +51,8 @@ export default async function DomainPage({
5251
analytics.track("report_viewed", { domain: normalized });
5352

5453
// Minimal prefetch: registration only, let sections stream progressively
55-
const queryClient = makeQueryClient();
54+
// Use getQueryClient() to ensure consistent query client across the request
55+
const queryClient = getQueryClient();
5656
void queryClient.prefetchQuery(
5757
trpc.domain.registration.queryOptions({ domain: normalized }),
5858
);

trpc/server.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import "server-only";
22

33
import { createTRPCOptionsProxy } from "@trpc/tanstack-react-query";
4+
import { cache } from "react";
45
import { appRouter } from "@/server/routers/_app";
56
import { createContext } from "@/trpc/init";
67
import { makeQueryClient } from "@/trpc/query-client";
78

9+
// Create a stable getter for the query client that will return the same client during
10+
// the same request. This ensures consistent query client behavior across multiple tRPC
11+
// calls within a single server request.
12+
export const getQueryClient = cache(makeQueryClient);
13+
814
// Strongly-typed tRPC proxy for server-side prefetching via queryOptions
915
export const trpc = createTRPCOptionsProxy({
1016
ctx: createContext,
1117
router: appRouter,
12-
queryClient: makeQueryClient,
18+
queryClient: getQueryClient,
1319
});

0 commit comments

Comments
 (0)