Skip to content

fix(query-core): exclude queries without data from isStatic - #12497

Merged
TkDodo merged 2 commits into
mainfrom
tkdodo/fix/static-query-without-data
Nov 2, 2026
Merged

TkDodo merged 2 commits into
mainfrom
tkdodo/fix/static-query-without-data

Conversation

@TkDodo

@TkDodo TkDodo commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

🎯 Changes

query.isStatic() should return false if the query has no data. This lets active static queries refetch after reset or a failed first fetch.

Alternative to #12122. The data check belongs in isStatic(), so refetchQueries can keep its existing filter. isStaleByTime keeps its per-observer check.

Tests cover reset, invalidation after a failed first fetch, and reset with initialData: 0. Both regression tests failed before the fix.

✅ 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
    • Static queries without cached data can now retry or refetch after invalidation, reset, or an explicit refetch.
    • Queries with a configured static stale time are treated as static only when they have data. After a reset, queries with initial data remain static and are not refetched.

@changeset-bot

changeset-bot Bot commented Nov 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 19c0830

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
@tanstack/query-core Patch
@tanstack/angular-query-experimental Patch
@tanstack/lit-query Patch
@tanstack/preact-query Patch
@tanstack/query-async-storage-persister Patch
@tanstack/query-broadcast-client-experimental Patch
@tanstack/query-devtools Patch
@tanstack/query-persist-client-core Patch
@tanstack/query-sync-storage-persister Patch
@tanstack/react-query Patch
@tanstack/solid-query Patch
@tanstack/svelte-query Patch
@tanstack/vue-query Patch
@tanstack/preact-query-devtools Patch
@tanstack/preact-query-persist-client Patch
@tanstack/react-query-devtools Patch
@tanstack/solid-query-devtools Patch
@tanstack/svelte-query-devtools Patch
@tanstack/vue-query-devtools Patch
@tanstack/react-query-persist-client Patch
@tanstack/solid-query-persist-client Patch
@tanstack/svelte-query-persist-client Patch
@tanstack/react-query-next-experimental Patch
@tanstack/eslint-plugin-query Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@nx-cloud

nx-cloud Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 19c0830

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 9m 46s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 35s View ↗

☁️ Nx Cloud last updated this comment at 2026-11-02 20:29:40 UTC

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

1 package(s) bumped directly, 23 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/query-core 5.105.2 → 5.105.3 Changeset
@tanstack/angular-query-experimental 5.105.2 → 5.105.3 Dependent
@tanstack/eslint-plugin-query 5.105.2 → 5.105.3 Dependent
@tanstack/lit-query 0.2.33 → 0.2.34 Dependent
@tanstack/preact-query 5.105.2 → 5.105.3 Dependent
@tanstack/preact-query-devtools 5.105.2 → 5.105.3 Dependent
@tanstack/preact-query-persist-client 5.105.2 → 5.105.3 Dependent
@tanstack/query-async-storage-persister 5.105.2 → 5.105.3 Dependent
@tanstack/query-broadcast-client-experimental 5.105.2 → 5.105.3 Dependent
@tanstack/query-devtools 5.105.2 → 5.105.3 Dependent
@tanstack/query-persist-client-core 5.105.2 → 5.105.3 Dependent
@tanstack/query-sync-storage-persister 5.105.2 → 5.105.3 Dependent
@tanstack/react-query 5.105.2 → 5.105.3 Dependent
@tanstack/react-query-devtools 5.105.2 → 5.105.3 Dependent
@tanstack/react-query-next-experimental 5.105.2 → 5.105.3 Dependent
@tanstack/react-query-persist-client 5.105.2 → 5.105.3 Dependent
@tanstack/solid-query 5.105.2 → 5.105.3 Dependent
@tanstack/solid-query-devtools 5.105.2 → 5.105.3 Dependent
@tanstack/solid-query-persist-client 5.105.2 → 5.105.3 Dependent
@tanstack/svelte-query 6.3.8 → 6.3.9 Dependent
@tanstack/svelte-query-devtools 6.3.8 → 6.3.9 Dependent
@tanstack/svelte-query-persist-client 6.3.8 → 6.3.9 Dependent
@tanstack/vue-query 5.105.2 → 5.105.3 Dependent
@tanstack/vue-query-devtools 6.3.8 → 6.3.9 Dependent

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d6b2b64 and 19c0830.

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

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

Walkthrough

Query.isStatic() now returns false when a query has no data. Tests cover invalidation and reset behavior for active static queries, and a changeset describes the update.

Changes: Static Queries Without Data

Layer / File(s) Summary
Static query data check and reset behavior
packages/query-core/src/query.ts, packages/query-core/src/__tests__/queryClient.test.tsx, .changeset/static-query-without-data.md
Query.isStatic() returns false when query data is undefined. Tests cover refetching after invalidation or reset when data is absent, and restoring configured initial data without fetching. The changeset describes refetching static queries without data after reset, invalidation, or explicit refetch.

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

Change: Bug fix

Suggested reviewers: sukvvon

Merge Risk: Minimal · up to 19c08

Static queries without data can refetch after a reset or failed initial fetch. No merge-blocking risk is identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: excluding queries without data from isStatic().
Description check Passed The description explains the change, motivation, implementation approach, tests, and release impact. The AI contribution policy checklist item remains unchecked, but the required sections are otherwis…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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: Description check

Explanation

The description explains the change, motivation, implementation approach, tests, and release impact. The AI contribution policy checklist item remains unchecked, but the required sections are otherwise complete.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files. (1 skipped: 1 unsupported.)

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • 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

@pkg-pr-new

pkg-pr-new Bot commented Nov 2, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@12497

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@12497

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@12497

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@12497

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@12497

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@12497

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@12497

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@12497

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@12497

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@12497

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@12497

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@12497

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@12497

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@12497

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@12497

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@12497

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@12497

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@12497

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@12497

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@12497

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@12497

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@12497

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@12497

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@12497

commit: 19c0830

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 11.84 KB (+0.01% 🔺)
react minimal 8.66 KB (-0.06% 🔽)

@TkDodo
TkDodo merged commit 969e580 into main Nov 2, 2026
9 checks passed
@TkDodo
TkDodo deleted the tkdodo/fix/static-query-without-data branch November 2, 2026 20:30
@github-actions github-actions Bot mentioned this pull request Nov 2, 2026
arkadia-agents Bot pushed a commit to arkadia-so/query that referenced this pull request Nov 4, 2026
arkadia-agents Bot pushed a commit to arkadia-so/query that referenced this pull request Nov 4, 2026
arkadia-agents Bot pushed a commit to arkadia-so/query that referenced this pull request Nov 4, 2026
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