Skip to content

fix: drop dead imports from generated React templates - #498

Open
WaryaWayne wants to merge 2 commits into
TanStack:mainfrom
WaryaWayne:fix/router-unused-imports
Open

fix: drop dead imports from generated React templates#498
WaryaWayne wants to merge 2 commits into
TanStack:mainfrom
WaryaWayne:fix/router-unused-imports

Conversation

@WaryaWayne

@WaryaWayne WaryaWayne commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Every fresh scaffold that includes tanstack-query ships TypeScript errors out of the box. Generated projects set noUnusedLocals: 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 build doesn'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 runs tsc.

Reproduce

npx @tanstack/cli create demo --add-ons tanstack-query -y
cd demo && npx tsc --noEmit
src/router.tsx(4,1): error TS6133: 'ReactNode' is declared but its value is never read.
src/router.tsx(5,1): error TS6133: 'QueryClient' is declared but its value is never read.
src/router.tsx(7,8): error TS6133: 'TanstackQueryProvider' is declared but its value is never read.

Add tRPC and you also get:

src/integrations/tanstack-query/root-provider.tsx(2,23): error TS6133: 'QueryClientProvider' is declared but its value is never read.
src/routes/api.trpc.$.tsx(1,1): error TS6133: 'createServerFileRoute' is declared but its value is never read.
src/routes/api.trpc.$.tsx(1,10): error TS2305: Module '"@tanstack/react-start/server"' has no exported member 'createServerFileRoute'.

What's wrong

1. project/base/src/router.tsx.ejs (commit 1) — the tanstack-query branch imports four things, but QueryClient is never referenced in any branch, and ReactNode / the TanstackQueryProvider default export are referenced only inside the addOnEnabled.tRPC Wrap block. Only getContext and setupRouterSsrQueryIntegration are used unconditionally. Fix: gate the two tRPC-only imports behind addOnEnabled.tRPC, delete QueryClient.

2. add-ons/tRPC/assets/src/routes/api.trpc.$.tsx (commit 2) — imports createServerFileRoute, but the route body already uses the current API (createFileRoute with server: { 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 imports QueryClientProvider but renders TRPCProvider; setupRouterSsrQueryIntegration is what supplies the query client.

setupRouterSsrQueryIntegration is deliberately left alone — it's used further down the router template, and removing it silently breaks SSR query dehydration. Solid's router.tsx.ejs is already correct.

Split into two commits, one per concern, with a changeset each.

Verification

Scaffolded with the built CLI, fully installed, typechecked and built:

Scaffold Before After
--add-ons tanstack-query 3 errors tsc --noEmit exit 0
--add-ons tanstack-query,tRPC 4 errors 1 error (unrelated, below)

vite build on 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

  • Bug Fixes
    • Fixed generated React projects with TanStack Query and tRPC so they no longer include unused or invalid imports.
    • Corrected the generated tRPC API route to properly handle both GET and POST requests.
    • Resolved scaffold validation errors when unused-local checks are enabled.
  • Chores
    • Added release notes documenting the generated project fixes.

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.
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Generated tRPC scaffold

Layer / File(s) Summary
Migrate the generated tRPC route
packages/create/src/frameworks/react/add-ons/tRPC/assets/src/routes/api.trpc.$.tsx, .changeset/trpc-dead-imports.md
The tRPC route exports a TanStack Router route handling GET and POST through fetchRequestHandler, replacing createServerFileRoute.
Clean up generated provider imports
packages/create/src/frameworks/react/project/base/src/router.tsx.ejs, packages/create/src/frameworks/react/add-ons/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejs, .changeset/router-unused-imports.md
Router and provider templates remove unused QueryClient and QueryClientProvider imports and gate ReactNode and TanstackQueryProvider behind tRPC availability.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: removing dead imports from generated React templates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between efbc8d5 and 9738b2f.

📒 Files selected for processing (5)
  • .changeset/router-unused-imports.md
  • .changeset/trpc-dead-imports.md
  • packages/create/src/frameworks/react/add-ons/tRPC/assets/src/routes/api.trpc.$.tsx
  • packages/create/src/frameworks/react/add-ons/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejs
  • packages/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

Comment on lines +9 to +12
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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant