fix: drop dead imports from generated React templates - #498
Conversation
The tanstack-query branch of the router template imports ReactNode, QueryClient and the TanstackQueryProvider default export whenever the add-on is enabled, but ReactNode and TanstackQueryProvider are only referenced inside the tRPC `Wrap` block and QueryClient is never referenced at all. Generated projects set `noUnusedLocals: true`, so a fresh scaffold ships code that violates its own tsconfig. Gates the two tRPC-only imports behind `addOnEnabled.tRPC` and removes the QueryClient import outright. setupRouterSsrQueryIntegration is deliberately left alone — it is used, and removing it silently breaks SSR query dehydration.
api.trpc.$.tsx imports createServerFileRoute from
'@tanstack/react-start/server'. The route already uses
`createFileRoute(...)({ server: { handlers } })`, and that symbol is no longer
exported, so the import is both unused (TS6133) and unresolvable (TS2305).
The tRPC branch of root-provider.tsx imports QueryClientProvider but renders
TRPCProvider; setupRouterSsrQueryIntegration is what supplies the query
client.
Generated projects set `noUnusedLocals: true`, so both surface as errors in a
fresh `--add-ons tanstack-query,tRPC` scaffold.
📝 WalkthroughWalkthroughThe generated React scaffolds now use TanStack Router for the tRPC API route and remove unused or incorrectly unconditional React Query imports from router and provider templates. ChangesGenerated tRPC scaffold
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.changeset/trpc-dead-imports.md:
- Around line 9-12: Update the query-client description in the changeset so it
states that getContext() creates the QueryClient and
setupRouterSsrQueryIntegration receives that existing client to register SSR
query integration, rather than implying the integration supplies or creates the
client.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 450a6105-c47f-499f-beac-68a7691cfc73
📒 Files selected for processing (5)
.changeset/router-unused-imports.md.changeset/trpc-dead-imports.mdpackages/create/src/frameworks/react/add-ons/tRPC/assets/src/routes/api.trpc.$.tsxpackages/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 with no reviewable changes (1)
- packages/create/src/frameworks/react/add-ons/tRPC/assets/src/routes/api.trpc.$.tsx
| and unresolvable. The tRPC branch of `root-provider.tsx` imported | ||
| `QueryClientProvider`, which it never renders — | ||
| `setupRouterSsrQueryIntegration` supplies the query client. Generated projects | ||
| set `noUnusedLocals: true`, so both showed up as errors in a fresh scaffold. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the query-client description.
getContext() creates the QueryClient; setupRouterSsrQueryIntegration receives that existing client to register SSR query integration. Please adjust this wording so the changeset does not misstate the responsibility of the integration.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.changeset/trpc-dead-imports.md around lines 9 - 12, Update the query-client
description in the changeset so it states that getContext() creates the
QueryClient and setupRouterSsrQueryIntegration receives that existing client to
register SSR query integration, rather than implying the integration supplies or
creates the client.
Every fresh scaffold that includes
tanstack-queryships TypeScript errors out of the box. Generated projects setnoUnusedLocals: true, and three imports in the templates are never used, all residue of earlier migrations that moved the code but left the import lines behind.To be precise about severity: this is not a broken build.
vite builddoesn't typecheck (esbuild strips types), so the apps build and run fine. It's red squiggles in every new project from the second it opens in an editor, and a hard failure the moment anyone runstsc.Reproduce
Add
tRPCand you also get:What's wrong
1.
project/base/src/router.tsx.ejs(commit 1) — thetanstack-querybranch imports four things, butQueryClientis never referenced in any branch, andReactNode/ theTanstackQueryProviderdefault export are referenced only inside theaddOnEnabled.tRPCWrap block. OnlygetContextandsetupRouterSsrQueryIntegrationare used unconditionally. Fix: gate the two tRPC-only imports behindaddOnEnabled.tRPC, deleteQueryClient.2.
add-ons/tRPC/assets/src/routes/api.trpc.$.tsx(commit 2) — importscreateServerFileRoute, but the route body already uses the current API (createFileRoutewithserver: { handlers: ... }). The migration landed, the import didn't get removed. That symbol is no longer exported at all, so it's both unused and unresolvable.3.
add-ons/tanstack-query/.../root-provider.tsx.ejs(commit 2) — the tRPC branch importsQueryClientProviderbut rendersTRPCProvider;setupRouterSsrQueryIntegrationis what supplies the query client.setupRouterSsrQueryIntegrationis deliberately left alone — it's used further down the router template, and removing it silently breaks SSR query dehydration. Solid'srouter.tsx.ejsis already correct.Split into two commits, one per concern, with a changeset each.
Verification
Scaffolded with the built CLI, fully installed, typechecked and built:
vite buildon the tRPC scaffold: exit 0. Unit suites green — 101@tanstack/cli, 248@tanstack/create.Prior art
Issue #272 ("Provider ... is not used"), closed by #356. The router imports are leftover residue of that fix — the Wrap block got gated, the imports did not. Not a duplicate, the still-live remainder.
Summary by CodeRabbit