Skip to content

Commit b1684db

Browse files
committed
fix: drop unused React Query imports from generated router
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.
1 parent efbc8d5 commit b1684db

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@tanstack/create': patch
3+
---
4+
5+
Drop unused React Query imports from the generated React `router.tsx`. The
6+
`tanstack-query` branch imported `ReactNode`, `QueryClient` and the
7+
`TanstackQueryProvider` default export whenever the add-on was enabled, but
8+
`ReactNode` and `TanstackQueryProvider` are only referenced inside the tRPC
9+
`Wrap` block and `QueryClient` was never referenced at all. Generated projects
10+
set `noUnusedLocals: true`, so a fresh scaffold shipped code that violates its
11+
own tsconfig. The two tRPC-only imports are now gated behind
12+
`addOnEnabled.tRPC` and the `QueryClient` import is removed.

packages/create/src/frameworks/react/project/base/src/router.tsx.ejs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { createRouter as createTanStackRouter } from '@tanstack/react-router'
22
import { routeTree } from './routeTree.gen'
3-
<% if (addOnEnabled['tanstack-query']) { %>
4-
import type { ReactNode } from 'react'
5-
import { QueryClient } from '@tanstack/react-query'
3+
<% if (addOnEnabled['tanstack-query']) { %><% if (addOnEnabled.tRPC) { %>
4+
import type { ReactNode } from 'react'<% } %>
65
import { setupRouterSsrQueryIntegration } from "@tanstack/react-router-ssr-query";
7-
import TanstackQueryProvider, { getContext } from './integrations/tanstack-query/root-provider'
6+
import <% if (addOnEnabled.tRPC) { %>TanstackQueryProvider, <% } %>{ getContext } from './integrations/tanstack-query/root-provider'
87
<% } %>
98
109
export function getRouter() {

0 commit comments

Comments
 (0)