fix(query-core): refetch static queries that have no data by S-jooyoung · Pull Request #12122 · TanStack/query · GitHub
Skip to content

fix(query-core): refetch static queries that have no data - #12122

Open
S-jooyoung wants to merge 1 commit into
TanStack:mainfrom
S-jooyoung:fix/query-core-reset-static-queries
Open

S-jooyoung wants to merge 1 commit into
TanStack:mainfrom
S-jooyoung:fix/query-core-reset-static-queries

Conversation

@S-jooyoung

@S-jooyoung S-jooyoung commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Changes

With staleTime: 'static', calling resetQueries clears the data but never refetches, so an active query stays in pending with fetchStatus: 'idle'. Same for a static query whose first fetch failed: invalidateQueries doesn't refetch it.

refetchQueries skips every static query, even one without data, while isStaleByTime treats a query without data as stale regardless of staleTime. This changes the filter to skip static queries only when they already have data. Static queries with data still aren't refetched.

Added two tests in queryClient.test.tsx (reset + invalidate after a failed fetch). Both fail before the change.

Note: this PR description was drafted with AI assistance. The AI policy box is left unchecked for that reason.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I have followed the AI contribution policy and fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Active static queries that have no cached data are now refetched when invalidated, reset, or explicitly refetched.
    • Static queries with cached data continue to be skipped during refetching.

`refetchQueries` skips every static query, so an active query whose
observers use `staleTime: 'static'` was not refetched after
`resetQueries` cleared its data, nor by `invalidateQueries` after its
first fetch failed. It was left without data and without a fetch.

Only skip static queries in `refetchQueries` when they already have
data, matching `isStaleByTime`, which treats a query without data as
stale regardless of `staleTime`.
@changeset-bot

changeset-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: TanStack/query/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8832d24f-53b0-40b6-b2f6-9f1a2182e825
📥 Commits

Reviewing files that changed from the base of the PR and between 4e413ae and 315e844.

📒 Files selected for processing: 3
  • .changeset/reset-static-queries.md
  • packages/query-core/src/__tests__/queryClient.test.tsx
  • packages/query-core/src/queryClient.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

refetchQueries now skips disabled queries and static queries only when they already have data. Tests cover invalidation and reset of active static queries without data. A patch changeset records the behavior.

Changes: Static query refetch behavior

Layer / File(s) Summary
Refetch static queries without data
packages/query-core/src/queryClient.ts, packages/query-core/src/__tests__/queryClient.test.tsx, .changeset/reset-static-queries.md
refetchQueries can refetch static queries without data. Tests verify that invalidation and reset refetch active static queries and restore cached data. The changeset describes the update.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: tkdodo

Merge Risk: ⚪ Minimal · up to 315e8

The change is mergeable after normal checks; no actionable issue is established in the supplied evidence.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description includes the required sections and accurately explains the change, tests, and changeset. However, the required AI contribution policy checklist item is explicitly unchecked. Review and follow the AI contribution policy, confirm full understanding of the code and any AI-generated content, then check the corresponding checklist item only when true.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: refetching static queries that have no data.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • 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

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

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant