Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
m2na7 wants to merge 1 commit into TanStack:main
base: main
Choose a base branch
Loading
from m2na7:refactor/replace-magic-number-with-constant

Conversation

Copy link

@m2na7 m2na7 commented Sep 1, 2025
edited by coderabbitai bot
Loading

Summary

  • Replace hardcoded 1000ms values with MIN_SUSPENSE_TIME_MS constant in suspense timer logic
  • Improves code readability and maintainability by eliminating magic numbers

Summary by CodeRabbit

  • Bug Fixes
    • Standardizes minimum Suspense timing to 1s, providing more predictable loading fallback behavior.
    • Aligns cache cleanup minimums in Suspense mode for consistent timing across queries.
    • No changes to the public API.

Copy link

coderabbitai bot commented Sep 1, 2025
edited
Loading

Walkthrough

Introduces 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

Cohort / File(s) Summary
Suspense timing minimum consolidation
packages/react-query/src/suspense.ts
Added MIN_SUSPENSE_TIME_MS constant; replaced hard-coded 1000 in clamp and defaultedOptions.gcTime; ensured universal minimum suspense timing; preserved function staleTime handling; no exported API changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my whiskers, count to one—
A thousand ticks, then hop, I’m done.
Timers clamped, no sudden leap,
Suspense now holds a steadier keep.
In burrows deep, I test and wait—
Then bound ahead at a measured rate. 🐇⏱️

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 0650eaf and adc481c.

📒 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /