Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<% if (addOnEnabled.tRPC) { %>
import { QueryClient } from "@tanstack/react-query";
import { QueryClient, useQueryClient } from "@tanstack/react-query";
import superjson from "superjson";
import { createTRPCClient, httpBatchStreamLink } from "@trpc/client";
import { createTRPCOptionsProxy } from "@trpc/tanstack-react-query";

import type { TRPCRouter } from "@/integrations/trpc/router";

import { TRPCProvider } from "@/integrations/trpc/react";

function getUrl() {
const base = (() => {
if (typeof window !== "undefined") return "";
Expand Down Expand Up @@ -40,6 +42,19 @@ export function getContext() {
trpc: serverHelpers,
};
}

export default function Provider({
children,
}: {
children: React.ReactNode;
}) {
const queryClient = useQueryClient();
return (
<TRPCProvider trpcClient={trpcClient} queryClient={queryClient}>
{children}
</TRPCProvider>
);
}
<% } else { %>
import { QueryClient } from '@tanstack/react-query'

Expand All @@ -49,4 +64,12 @@ export function getContext() {
queryClient,
};
}

export default function Provider({
children,
}: {
children: React.ReactNode;
}) {
return children;
}
<% } %>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"dependencies": {
"@tanstack/react-query": "^5.66.5",
"@tanstack/react-query-devtools": "^5.84.2"
"@tanstack/react-query-devtools": "^5.84.2",
"@tanstack/react-router-ssr-query": "^1.159.10"
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { createRouter as createTanStackRouter } from '@tanstack/react-router'
import { routeTree } from './routeTree.gen'
<% if (addOnEnabled['tanstack-query']) { %>
import { setupRouterSsrQueryIntegration } from '@tanstack/react-router-ssr-query'
import { getContext } from './integrations/tanstack-query/root-provider'
<% } %>

export function getRouter() {
<% if (addOnEnabled['tanstack-query']) { %>
const { queryClient, ...rest } = getContext()
<% } %>

const router = createTanStackRouter({
routeTree,
<% if (addOnEnabled['tanstack-query']) { %>
context: getContext(),
context: { queryClient, ...rest },
<% } else if (addOnEnabled['apollo-client']) { %>
context: {} as any,
<% } %>
Expand All @@ -17,6 +22,13 @@ export function getRouter() {
defaultPreloadStaleTime: 0,
})

<% if (addOnEnabled['tanstack-query']) { %>
setupRouterSsrQueryIntegration({
router,
queryClient,
})
<% } %>

return router
}

Expand Down