Skip to content

feat(tanstack-react-query): keyPrefix works without a feature flag - #7767

Merged
trpc-bot merged 4 commits into
v12from
cursor/key-prefix-just-works-0ee9
Nov 1, 2026
Merged

trpc-bot merged 4 commits into
v12from
cursor/key-prefix-just-works-0ee9

Conversation

@KATT

@KATT KATT commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Why

  • keyPrefix is stable, but you had to turn it on with a type argument: createTRPCContext<AppRouter, { keyPrefix: true }>().
  • The flag showed up in every procedure hover as featureFlags: { keyPrefix: false }.

What

  • createTRPCOptionsProxy takes its types from values, with one signature. The router type comes from client (or router), and the key types come from keyPrefix:

    const billing = createTRPCOptionsProxy({ client, queryClient, keyPrefix: 'billing' });
    billing.list.queryKey(); // [prefix: string[], path: string[], opts?: ...]

    A string gives prefixed key types, no keyPrefix gives unprefixed ones, and string | undefined gives 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>.

  • createTRPCContext is back to its single signature, and TRPCProvider takes keyPrefix without the flag. Key types from useTRPC() keep the unprefixed shape, because the prefix only arrives at render. The keys themselves include it.

  • Procedure types carry featureFlags only when keys are prefixed, so default hovers show just input, output, transformer and errorShape.

  • Docs: the Query Key Prefixing section drops the flag, and its createTRPCOptionsProxy example has no type argument.

Compatibility

  • No runtime change. Cache keys are the same with and without a prefix.
  • Every call that compiled before still compiles, with the same types:
    • createTRPCOptionsProxy<AppRouter>({ client, queryClient }) and createTRPCContext<AppRouter>() keep unprefixed key types. Code that indexes keys, like queryKey[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.
  • Not supported: an explicit router type argument together with keyPrefix, as in createTRPCOptionsProxy<AppRouter>({ …, keyPrefix }). It stays a type error, as it was before this PR. The error's doc says to leave the type argument out.
  • Newly allowed: keyPrefix on the provider of a context created without the flag.
  • ResolverDef['featureFlags'] is now optional. Only code that reads TDef['featureFlags'] directly would notice.

Testing

  • test/keyPrefix.test.tsx covers:
    • inferred prefixed keys
    • unprefixed keys from router
    • string | undefined
    • an explicit <AppRouter> with and without keyPrefix
    • the deprecated flags
    • the provider
    • queryKey[1]?.type
    • hovers
  • vitest run packages/tanstack-react-query (82 tests), pnpm typecheck-packages, pnpm typecheck-www, ESLint and Prettier all pass in v11/.
  • The Vercel tanstack-start-sse-chat failure on the first run came from a missing vercel.json stub on v12 for main's new example. 14d22541d added the stub on v12.
Open in Web Open in Cursor 

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

cursoragent and others added 2 commits November 1, 2026 10:40
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]>
@KATT
KATT requested review from a team as code owners November 1, 2026 10:47
@vercel

vercel Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
tanstack-start-sse-chat Error Error Nov 1, 2026 7:08pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@pkg-pr-new

pkg-pr-new Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@trpc/client

npm i https://pkg.pr.new/@trpc/client@7767

@trpc/next

npm i https://pkg.pr.new/@trpc/next@7767

@trpc/openapi

npm i https://pkg.pr.new/@trpc/openapi@7767

@trpc/react-query

npm i https://pkg.pr.new/@trpc/react-query@7767

@trpc/server

npm i https://pkg.pr.new/@trpc/server@7767

@trpc/tanstack-react-query

npm i https://pkg.pr.new/@trpc/tanstack-react-query@7767

@trpc/upgrade

npm i https://pkg.pr.new/@trpc/upgrade@7767

commit: d228d65

…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]>
cursor Bot pushed a commit that referenced this pull request Nov 1, 2026
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]>
cursor Bot pushed a commit that referenced this pull request Nov 1, 2026
… 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]>
@trpc-bot
trpc-bot merged commit 15635d1 into v12 Nov 1, 2026
42 checks passed
@trpc-bot
trpc-bot deleted the cursor/key-prefix-just-works-0ee9 branch November 1, 2026 19:13
cursor Bot pushed a commit that referenced this pull request Nov 3, 2026
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]>
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants