Repository navigation
fix(templates): create TanStack Query client per request in Next and SvelteKit - #1295
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Follow-up on the one SvelteKit fullstack live-test failure (
The single failure was a SvelteKit page-data fetch that a newer navigation cancelled. It hasn't recurred in 10 later runs, which points to timing rather than this change. Still, it's a 1-in-11 data point, so I'm not calling it resolved. |
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⛔ Files ignored due to path filters: 1
⚙️ Run configuration
⛔ Files ignored due to path filters: 1
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe templates change query-client creation in React and Svelte. Next.js tRPC consumers use context hooks and a provider. Svelte loading checks use ChangesQuery Client Lifecycle
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to
|
Queries are disabled during SvelteKit SSR, so isLoading is false and the server HTML rendered "Disconnected" and "No todos yet." before hydration. Use isPending so the server and first client render show the loading state.
Follows tRPC's App Router setup: utils/trpc exports makeTRPCClient() and the Providers component creates the client once with useState, next to the per-request query client.
Summary
Generated SSR apps shared one module-level TanStack
QueryClientbetween server renders, so cached query data could leak across users' requests. The server now creates a new client for each request. The browser still keeps a single client.Fixes #895
Changes
utils/trpc.tsnow exportsTRPCProvider/useTRPC(createTRPCContext),makeTRPCClient(), andgetQueryClient(), following tRPC's App Router setup. Server code gets a new client on every call; the browser reuses one singleton (environmentManager.isServer()).providers.tsxcreates the tRPC client once withuseState(makeTRPCClient), wraps children inTRPCProvider, and pages calluseTRPC(). This matches the TanStack Start template.utils/orpc.tsexportsgetQueryClient()in place of the singletonqueryClient, andproviders.tsxuses it.lib/orpc.tsexportscreateQueryClient()withenabled: browser. The client is created in+layout.svelte, so each server render gets its own client.ssr: false), TanStack Router and native apps run only on the client, so their singleton stays.Docs followed: TanStack Query's Advanced SSR guide (Next.js App Router
getQueryClient), tRPC's TanStack React Query setup and server-components docs, oRPC's TanStack Query integration docs, and TanStack Query's Svelte SSR docs.Verification
bun install,check-typesandbuild.bun run test:live run: next/self orpc, next/self trpc, next/hono trpc and svelte/hono orpc passed. svelte/self orpc failed on its first run with one aborted SvelteKit__data.jsoninvalidation request (net::ERR_ABORTED). It passed on retry and on 3 later runs from fresh run directories.next9/9 passed andsvelte14/14 passed.bun run checkandtest:ci(112 tests) passed.Summary by CodeRabbit