Conversation
📝 WalkthroughWalkthroughRefactors TanStack Query integration to stop using a module-level cached context. Changes
Sequence Diagram(s)sequenceDiagram
participant RouterSetup as Router Setup
participant Caller as Caller
participant GC as getContext()
participant QC as QueryClient
participant TRouter as createTanStackRouter
participant Provider as TanStackQueryProvider
participant SSR as setupRouterSsrQueryIntegration
RouterSetup->>GC: call getContext()
GC-->>RouterSetup: return context (includes QC)
RouterSetup->>TRouter: createTanStackRouter(..., context)
RouterSetup->>Provider: render Wrap with context prop
Provider->>QC: read queryClient from context
RouterSetup->>SSR: setupRouterSsrQueryIntegration({router, queryClient: QC})
SSR-->>RouterSetup: SSR integration configured
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/create/src/frameworks/react/add-ons/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejs (1)
40-45:⚠️ Potential issue | 🔴 CriticalReturn the new context object directly instead of assigning to an undeclared variable.
The
contextvariable at line 40 is assigned without being declared. This will cause a runtime error in the generatedreact + tanstack-query + tRPCtemplate.Suggested fix
export function getContext() { const queryClient = new QueryClient({ defaultOptions: { dehydrate: { serializeData: superjson.serialize }, hydrate: { deserializeData: superjson.deserialize }, }, }); const serverHelpers = createTRPCOptionsProxy({ client: trpcClient, queryClient: queryClient, }); - context = { + return { queryClient, trpc: serverHelpers, } - - return context }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/create/src/frameworks/react/add-ons/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejs` around lines 40 - 45, Replace the undeclared assignment to context with a direct return of the object: instead of setting context = { queryClient, trpc: serverHelpers } and returning context, return { queryClient, trpc: serverHelpers } directly from the function (locate the return in root-provider.tsx.ejs where queryClient and serverHelpers are in scope).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In
`@packages/create/src/frameworks/react/add-ons/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejs`:
- Around line 40-45: Replace the undeclared assignment to context with a direct
return of the object: instead of setting context = { queryClient, trpc:
serverHelpers } and returning context, return { queryClient, trpc: serverHelpers
} directly from the function (locate the return in root-provider.tsx.ejs where
queryClient and serverHelpers are in scope).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 8f586686-6d53-466e-be20-d9ce66d07b10
📒 Files selected for processing (3)
packages/create/src/frameworks/react/add-ons/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejspackages/create/src/frameworks/react/add-ons/tanstack-query/info.jsonpackages/create/src/frameworks/react/project/base/src/router.tsx.ejs
💤 Files with no reviewable changes (1)
- packages/create/src/frameworks/react/add-ons/tanstack-query/info.json
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/create/src/frameworks/react/add-ons/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejs (1)
28-45:⚠️ Potential issue | 🔴 CriticalReturn the fresh context directly.
Line 40 assigns to
contextwithout any declaration in this template, so the generated code will fail with a reference error at runtime or fail TypeScript compilation withCannot find name 'context'. TheTanStackQueryProvidercomponent expects this function to return the context object.🔧 Proposed fix
export function getContext() { const queryClient = new QueryClient({ defaultOptions: { dehydrate: { serializeData: superjson.serialize }, hydrate: { deserializeData: superjson.deserialize }, }, }); const serverHelpers = createTRPCOptionsProxy({ client: trpcClient, - queryClient: queryClient, + queryClient, }); - context = { + return { queryClient, trpc: serverHelpers, } - - return context }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/create/src/frameworks/react/add-ons/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejs` around lines 28 - 45, The getContext function currently assigns to an undeclared variable "context" causing a reference/TS error; change getContext to return the fresh context object directly (or declare a local const if you need the variable), e.g. build a local const (e.g., const context = { queryClient, trpc: serverHelpers }) and then return that const; update references to getContext/TanStackQueryProvider to use the returned object and avoid using a global "context" variable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In
`@packages/create/src/frameworks/react/add-ons/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejs`:
- Around line 28-45: The getContext function currently assigns to an undeclared
variable "context" causing a reference/TS error; change getContext to return the
fresh context object directly (or declare a local const if you need the
variable), e.g. build a local const (e.g., const context = { queryClient, trpc:
serverHelpers }) and then return that const; update references to
getContext/TanStackQueryProvider to use the returned object and avoid using a
global "context" variable.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 883dad3c-7b50-4797-a17a-c0b9a701c294
📒 Files selected for processing (2)
packages/create/src/frameworks/react/add-ons/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejspackages/create/src/frameworks/react/project/base/src/router.tsx.ejs
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/create/src/frameworks/react/project/base/src/router.tsx.ejs
Tested locally with
node ./cli/packages/cli/dist/index.js create my-app3 --add-ons tanstack-querySummary by CodeRabbit
Refactor
Chores