-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
refactor(react-query): replace magic number with named constant in suspense timers #9607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(react-query): replace magic number with named constant in suspense timers #9607
Conversation
WalkthroughIntroduces a local MIN_SUSPENSE_TIME_MS constant (1000 ms) in ensureSuspenseTimers and replaces hard-coded 1000 usages. Applies the minimum to clamp logic for suspense timing and to defaultedOptions.gcTime. Behavior for function-based staleTime remains wrapped with clamp. No public API signatures changed. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/react-query/src/suspense.ts (1)
27-27
: Nice extraction; consider module-level const and de-hardcode the comment.
- Moving
MIN_SUSPENSE_TIME_MS
to module scope avoids redeclaration on every call and makes reuse trivial if more sites need the same minimum.- The preceding comment still hardcodes “1000ms”. Prefer wording that references the constant (e.g., “minimum suspense time”) to prevent drift if the value changes.
Apply within this hunk:
- const MIN_SUSPENSE_TIME_MS = 1000 + // Use module-level MIN_SUSPENSE_TIME_MS (see top of file)Add outside this hunk (top-level, after imports):
// Minimum suspense-related time window to avoid thrashing on remounts const MIN_SUSPENSE_TIME_MS = 1000
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/react-query/src/suspense.ts
(2 hunks)
🔇 Additional comments (3)
packages/react-query/src/suspense.ts (3)
29-31
: Clamp logic reads well and preserves previous semantics.Keeps the 'static' sentinel intact and enforces the minimum for numeric/undefined values. Looks good.
38-40
: Consistent minimum for gcTime in Suspense.Aligns gcTime with the same minimum; Infinity remains unaffected. LGTM.
21-42
: No additional magic 1000ms literals in source—only in tests verifying behavior; no further changes needed.
View your CI Pipeline Execution ↗ for commit adc481c
☁️ Nx Cloud last updated this comment at |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9607 +/- ##
===========================================
+ Coverage 45.15% 84.42% +39.27%
===========================================
Files 208 26 -182
Lines 8323 366 -7957
Branches 1886 107 -1779
===========================================
- Hits 3758 309 -3449
+ Misses 4118 48 -4070
+ Partials 447 9 -438 🚀 New features to boost your workflow:
|
Summary
MIN_SUSPENSE_TIME_MS
constant in suspense timer logicSummary by CodeRabbit