Repository navigation
feat(tanstack-react-query): keyPrefix works without a feature flag - #7767
Conversation
createTRPCOptionsProxy infers key types from the keyPrefix you pass.
TRPCProvider accepts keyPrefix without a flag; useTRPC key types keep
the unprefixed shape. The old { keyPrefix: true } type argument still
compiles and is deprecated. Procedure types no longer carry
featureFlags unless keys are prefixed.
Co-authored-by: alexander <[email protected]>
…usage guide Co-authored-by: alexander <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
@trpc/client
@trpc/next
@trpc/openapi
@trpc/react-query
@trpc/server
@trpc/tanstack-react-query
@trpc/upgrade
commit: |
…and keyPrefix with one signature
The router type comes from `client` (or `router`) and the key types from
`keyPrefix`, so the four overloads go. `<AppRouter>` alone and the
deprecated `<AppRouter, { keyPrefix: true }>` still compile.
createTRPCContext is back to its single signature.
Co-authored-by: alexander <[email protected]>
main's examples/tanstack-start-sse-chat deploys to its own Vercel project, whose root directory doesn't exist on v12, so every pull request into v12 got a failed deployment from it (#7767). The same stub as the other v11 projects' skips it. Co-authored-by: alexander <[email protected]>
Co-authored-by: alexander <[email protected]>
… a value, with one signature The human asked on #7767 why createTRPCOptionsProxy doesn't use the routerType<> approach, and that every client-facing entry point work the same way. Records the rule, the 2026-11-01 audit (only createTrpcContext takes a type argument) and the positional public types left for a bag. client.md no longer says createTrpcClient<AppRouter>({ links }) works: its overloads went with Q17.3. Co-authored-by: alexander <[email protected]>
Brings main up to db643ba: query handles and the live docs demos (#7759, #7817), the release commit check (#7834), the Prisma starter's generate step (#7806), the package links test (#7809), the sponsor cards (#7821, #7835), the PR template's AI model section (#7836) and v11.23.0. - v11/scripts/check-release-commit.ts names v11/lerna.json and v11/packages/* (git gives repo-root paths) and undoes from the repo root; v11/package.json takes its preversion and postversion scripts and its effect dependencies. - tanstack-react-query combines main's handles with #7767's feature flags: handles.ts reads keyPrefix through inferFeatureFlags, and Context.tsx passes the internal renderHandleVerbs flag through a variable. - main's live demos took the ```demo fence and the demo-slot class, so the kitchen sink's fence is ```kitchen-sink and its slot is kitchen-sink-slot. - www type-checks against v11's and v12's TanStack Query integrations, so v12's TanStack Query family moves to 5.105.0 with main. The react-spa cache test now persists through the transformer like the app, since 5.105.0 only falls back to initialPageParam for an undefined first cursor. - www/build/package-links.test.ts reads v11/packages. - turbo.json drops the Prisma starter's generate and lint entries. - The PR template keeps v12's and adds main's AI model section. - The lockfile is rebuilt from v12's, adding only the new dependencies. Co-authored-by: Alex / KATT <[email protected]>
|
This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you. |
Why
keyPrefixis stable, but you had to turn it on with a type argument:createTRPCContext<AppRouter, { keyPrefix: true }>().featureFlags: { keyPrefix: false }.What
createTRPCOptionsProxytakes its types from values, with one signature. The router type comes fromclient(orrouter), and the key types come fromkeyPrefix:A string gives prefixed key types, no
keyPrefixgives unprefixed ones, andstring | undefinedgives either shape. This replaces the four overloads in this PR's first version. They existed only because TypeScript can't infer the other type arguments once you write<AppRouter>.createTRPCContextis back to its single signature, andTRPCProvidertakeskeyPrefixwithout the flag. Key types fromuseTRPC()keep the unprefixed shape, because the prefix only arrives at render. The keys themselves include it.Procedure types carry
featureFlagsonly when keys are prefixed, so default hovers show justinput,output,transformeranderrorShape.Docs: the Query Key Prefixing section drops the flag, and its
createTRPCOptionsProxyexample has no type argument.Compatibility
createTRPCOptionsProxy<AppRouter>({ client, queryClient })andcreateTRPCContext<AppRouter>()keep unprefixed key types. Code that indexes keys, likequeryKey[1]?.type, still type-checks.<AppRouter, { keyPrefix: true }>and{ keyPrefix: false }keep the same types and prop rules. The JSDoc calls them deprecated. Without overloads, editors don't strike them through.keyPrefix, as increateTRPCOptionsProxy<AppRouter>({ …, keyPrefix }). It stays a type error, as it was before this PR. The error's doc says to leave the type argument out.keyPrefixon the provider of a context created without the flag.ResolverDef['featureFlags']is now optional. Only code that readsTDef['featureFlags']directly would notice.Testing
test/keyPrefix.test.tsxcovers:routerstring | undefined<AppRouter>with and withoutkeyPrefixqueryKey[1]?.typevitest run packages/tanstack-react-query(82 tests),pnpm typecheck-packages,pnpm typecheck-www, ESLint and Prettier all pass inv11/.tanstack-start-sse-chatfailure on the first run came from a missingvercel.jsonstub onv12formain's new example.14d22541dadded the stub onv12.Need help on this PR? Tag
@codesmith-botwith what you need.