Skip to content

Commit b5555e1

Browse files
authored
feat: export getQueryClient and update comment on usage (#513)
1 parent adc4b43 commit b5555e1

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

apps/web/src/trpc/server.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ const createContext = cache(async () => {
2424
})
2525

2626
/**
27-
* Avoid using this directly in a server component to fetch data for rendering
28-
* (i.e. `queryClient.fetchQuery(trpc.some.procedure.queryOptions()`)), as any thrown errors
29-
* will not be properly handled by `@tanstack/react-query`.
30-
* Instead, use a try-catch block around your tRPC data fetching code in the server component
31-
* and handle errors appropriately (e.g., by rendering an error message or redirecting).
32-
* Read https://tanstack.com/query/latest/docs/framework/react/guides/advanced-ssr#data-ownership-and-revalidation
27+
* Only use this function if you really need to use the data both on the server as well as inside client components
28+
* and understand the tradeoffs explained in the [Advanced Server Rendering](https://tanstack.com/query/latest/docs/framework/react/guides/advanced-ssr#data-ownership-and-revalidation) guide.
29+
* Always use a try-catch block if you use this function to fetch data on the server component and there are specific errors you want to handle.
3330
*/
34-
const getQueryClient = cache(createQueryClient)
31+
export const getQueryClient = cache(createQueryClient)
3532

3633
export const trpc = createTRPCOptionsProxy<AppRouter>({
3734
router: appRouter,

0 commit comments

Comments
 (0)