fix(tanstack-react-query): add prefix support for mutation options#7370
fix(tanstack-react-query): add prefix support for mutation options#7370tmkx wants to merge 1 commit into
Conversation
Add prefix parameter to mutation options to support key prefixing from proxy/context level. This allows mutation key prefixes to be defined at a higher level while still allowing per-mutation overrides.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThis PR fixes a bug where ChangesKey Prefix Threading
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/tanstack-react-query/src/internals/mutationOptions.ts (1)
111-114: Runtime fix is correct; the call site's static type formutationKeyremains inconsistent withmutationKey()The
opts?.keyPrefix ?? prefixfallback correctly aligns the runtimemutationKeyvalue with whatmutationKey()produces. However,DecorateMutationProcedure<TDef>declares:mutationOptions: TRPCMutationOptions<TDef>; // TFeatureFlags defaults to DefaultFeatureFlags mutationKey: () => TRPCMutationKey<TDef['featureFlags']['keyPrefix']>;Because the second generic of
TRPCMutationOptionsdefaults toDefaultFeatureFlagsrather thanTDef['featureFlags'], the TypeScript type ofmutationOptions().mutationKeyisTRPCMutationKey<DefaultFeatureFlags['keyPrefix']>, notTRPCMutationKey<TDef['featureFlags']['keyPrefix']>. This means consumers with a prefix-enabled proxy see a less-precise type frommutationOptions()than frommutationKey(), even though the runtime values are now identical.The fix is a one-line change in
createOptionsProxy.ts,DecorateMutationProcedure<TDef>:♻️ Proposed type fix
- mutationOptions: TRPCMutationOptions<TDef>; + mutationOptions: TRPCMutationOptions<TDef, TDef['featureFlags']>;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/tanstack-react-query/src/internals/mutationOptions.ts` around lines 111 - 114, DecorateMutationProcedure<TDef>'s mutationOptions type uses TRPCMutationOptions with the default feature flags, causing mutationOptions().mutationKey to be typed with DefaultFeatureFlags; update the declaration in createOptionsProxy.ts so mutationOptions passes TDef['featureFlags'] as the second generic (e.g. change mutationOptions: TRPCMutationOptions<TDef> to mutationOptions: TRPCMutationOptions<TDef, TDef['featureFlags']>) so its mutationKey type matches the existing mutationKey(): TRPCMutationKey<TDef['featureFlags']['keyPrefix']>.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/tanstack-react-query/src/internals/mutationOptions.ts`:
- Around line 111-114: DecorateMutationProcedure<TDef>'s mutationOptions type
uses TRPCMutationOptions with the default feature flags, causing
mutationOptions().mutationKey to be typed with DefaultFeatureFlags; update the
declaration in createOptionsProxy.ts so mutationOptions passes
TDef['featureFlags'] as the second generic (e.g. change mutationOptions:
TRPCMutationOptions<TDef> to mutationOptions: TRPCMutationOptions<TDef,
TDef['featureFlags']>) so its mutationKey type matches the existing
mutationKey(): TRPCMutationKey<TDef['featureFlags']['keyPrefix']>.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d87ae420-4ba9-43ae-9b79-418798be8697
📒 Files selected for processing (3)
packages/tanstack-react-query/src/internals/createOptionsProxy.tspackages/tanstack-react-query/src/internals/mutationOptions.tspackages/tanstack-react-query/test/mutationOptions.test.tsx
Closes #7369
🎯 Changes
Add prefix parameter to mutation options to support key prefixing from proxy/context level. This allows mutation key prefixes to be defined at a higher level while still allowing per-mutation overrides.
✅ Checklist
Summary by CodeRabbit
Bug Fixes
Tests