canastro
canastro
TtRPC
Created by canastro on 4/18/2025 in #❓-help
`useSuspenseQuery` returns unexpected `.json` and `.metadata` (SuperJSON)
I'm using pnpm and node v22 Some relevant packages:
"@tanstack/react-query": "^5.74.4",
"@tanstack/react-query-devtools": "^5.74.4",
"@trpc/client": "^11.1.0",
"@trpc/server": "^11.1.0",
"@trpc/tanstack-react-query": "^11.1.0",
"next": "15.2.2",
"@tanstack/react-query": "^5.74.4",
"@tanstack/react-query-devtools": "^5.74.4",
"@trpc/client": "^11.1.0",
"@trpc/server": "^11.1.0",
"@trpc/tanstack-react-query": "^11.1.0",
"next": "15.2.2",
4 replies
TtRPC
Created by canastro on 4/18/2025 in #❓-help
`useSuspenseQuery` returns unexpected `.json` and `.metadata` (SuperJSON)
This is my TRPCProvider:
function TRPCReactProvider(props: { children: ReactNode }) {
const params = useParams<{ slug?: string }>();
const queryClient = getQueryClient();
const slug = params.slug ?? currentSlug;

const [trpcClient] = useState(() =>
createTRPCClient<AppRouter>({
links: [
loggerLink({
enabled: (op) =>
process.env.NODE_ENV === "development" ||
(op.direction === "down" && op.result instanceof Error),
}),
httpBatchStreamLink({
transformer: SuperJSON,
headers: () => {
if (!slug) return {};
return { "x-publication-slug": slug };
},
url: `${getBaseUrl()}/api/trpc`,
}),
],
})
);

return (
<QueryClientProvider client={queryClient}>
<TRPCProvider trpcClient={trpcClient} queryClient={queryClient}>
<ReactQueryDevtools initialIsOpen={false} />
{props.children}
</TRPCProvider>
</QueryClientProvider>
);
}
function TRPCReactProvider(props: { children: ReactNode }) {
const params = useParams<{ slug?: string }>();
const queryClient = getQueryClient();
const slug = params.slug ?? currentSlug;

const [trpcClient] = useState(() =>
createTRPCClient<AppRouter>({
links: [
loggerLink({
enabled: (op) =>
process.env.NODE_ENV === "development" ||
(op.direction === "down" && op.result instanceof Error),
}),
httpBatchStreamLink({
transformer: SuperJSON,
headers: () => {
if (!slug) return {};
return { "x-publication-slug": slug };
},
url: `${getBaseUrl()}/api/trpc`,
}),
],
})
);

return (
<QueryClientProvider client={queryClient}>
<TRPCProvider trpcClient={trpcClient} queryClient={queryClient}>
<ReactQueryDevtools initialIsOpen={false} />
{props.children}
</TRPCProvider>
</QueryClientProvider>
);
}
4 replies