feat(query-core): add enforceQueryGcTime query client option#10521
feat(query-core): add enforceQueryGcTime query client option#10521Tseian wants to merge 1 commit intoTanStack:mainfrom
Conversation
📝 WalkthroughWalkthroughA new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/query-core/src/queryClient.ts (1)
581-600:⚠️ Potential issue | 🟠 MajorApply enforcement before returning already-defaulted options.
Line 581 returns
_defaultedoptions before Line 598 can overwritegcTime. A defaulted options object produced elsewhere can therefore bypassenforceQueryGcTimeand create/cache a query with the originalgcTime.🐛 Proposed fix
if (options._defaulted) { + if (this.#enforceQueryGcTime !== undefined) { + options.gcTime = this.#enforceQueryGcTime + } return options as DefaultedQueryObserverOptions< TQueryFnData, TError,🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/query-core/src/queryClient.ts` around lines 581 - 600, The early return when options._defaulted bypasses the enforceQueryGcTime override; before returning an already-defaulted options object (check options._defaulted), apply the enforcement by setting options.gcTime = this.#enforceQueryGcTime when this.#enforceQueryGcTime is not undefined, then return the casted DefaultedQueryObserverOptions. For the non-_defaulted path, keep the existing merge that builds defaultedOptions and continue to apply the same this.#enforceQueryGcTime override to defaultedOptions.gcTime as currently implemented.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@packages/query-core/src/queryClient.ts`:
- Around line 581-600: The early return when options._defaulted bypasses the
enforceQueryGcTime override; before returning an already-defaulted options
object (check options._defaulted), apply the enforcement by setting
options.gcTime = this.#enforceQueryGcTime when this.#enforceQueryGcTime is not
undefined, then return the casted DefaultedQueryObserverOptions. For the
non-_defaulted path, keep the existing merge that builds defaultedOptions and
continue to apply the same this.#enforceQueryGcTime override to
defaultedOptions.gcTime as currently implemented.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 85aefe41-14a4-4335-aa2e-4d53535c49de
📒 Files selected for processing (5)
.changeset/warm-windows-kiss.mddocs/reference/QueryClient.mdpackages/query-core/src/__tests__/queryClient.test.tsxpackages/query-core/src/queryClient.tspackages/query-core/src/types.ts
🎯 Changes
✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
New Features
enforceQueryGcTimeoption to QueryClient configuration, allowing developers to enforce a single garbage collection time across all queries, overriding per-query or global settings.Documentation
enforceQueryGcTimeconfiguration option and usage examples.Tests
enforceQueryGcTimebehavior and precedence rules.