Files
calendar/apps/web/app/_trpc/query-client.ts
T
be883aac02 perf: Remove ssrInit from layout and event-types (#20368)
* perf: Remove ssrInit from layout and event-types

* remove ssg file since not used

* refator trpc usage in app router

* fix

---------

Co-authored-by: hbjORbj <sldisek783@gmail.com>
2025-03-26 22:04:52 -03:00

38 lines
1.1 KiB
TypeScript

"use client";
import { QueryClient } from "@tanstack/react-query";
import { TRPCClientError } from "@trpc/client";
const MAX_QUERY_RETRIES = 3;
const isTRPCClientError = (cause: unknown): cause is TRPCClientError<any> => {
return cause instanceof TRPCClientError;
};
export const queryClient = new QueryClient({
// these configurations are copied from "packages/trpc/react/trpc.ts"
defaultOptions: {
queries: {
/**
* 1s should be enough to just keep identical query waterfalls low
* @example if one page components uses a query that is also used further down the tree
*/
staleTime: 1000,
/**
* Retry `useQuery()` calls depending on this function
*/
retry(failureCount, error) {
if (isTRPCClientError(error) && error.data) {
const { code } = error.data;
if (code === "BAD_REQUEST" || code === "FORBIDDEN" || code === "UNAUTHORIZED") {
// if input data is wrong or you're not authorized there's no point retrying a query
return false;
}
}
return failureCount < MAX_QUERY_RETRIES;
},
},
},
});