Skip to content

test({react,preact}-query/useSuspenseQueries): add test for not suspending but only refetching the stale query when one query has fresh and the other has stale cached data#10345

Merged
sukvvon merged 1 commit intomainfrom
test/useSuspenseQueries-fresh-stale-mixed-cache
Mar 28, 2026
Merged

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Mar 28, 2026

🎯 Changes

Add test for the mixed cache state (fresh + stale) scenario in useSuspenseQueries. Verifies that when one query has fresh cached data and the other has stale cached data:

  • Neither query triggers a suspend
  • Only the stale query performs a background refetch
  • The fresh query is never refetched

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for useSuspenseQueries to verify correct behavior when queries have different freshness states at mount, ensuring stale queries refresh in the background without affecting fresh queries.

…nding but only refetching the stale query when one query has fresh and the other has stale cached data
@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Mar 28, 2026

View your CI Pipeline Execution ↗ for commit 219ffcb

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

☁️ Nx Cloud last updated this comment at 2026-03-28 08:00:24 UTC

@sukvvon sukvvon self-assigned this Mar 28, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 28, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 219ffcb

@github-actions
Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 11.98 KB (0%)
react minimal 9.01 KB (0%)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0cf00eed-8a78-452e-9390-b3e9f2d7097e

📥 Commits

Reviewing files that changed from the base of the PR and between 0e766f2 and 219ffcb.

📒 Files selected for processing (2)
  • packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx
  • packages/react-query/src/__tests__/useSuspenseQueries.test.tsx

📝 Walkthrough

Walkthrough

This PR adds identical test cases to both react-query and preact-query test suites that verify useSuspenseQueries behavior when queries have mixed freshness states at mount: one stale query triggers background refetch while one fresh query remains unchanged and does not trigger its query function.

Changes

Cohort / File(s) Summary
useSuspenseQueries Test Cases
packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx, packages/react-query/src/__tests__/useSuspenseQueries.test.tsx
Added test case verifying that when two queries have different freshness states, the stale query background-refetches while the fresh query remains untouched, and initial render does not suspend showing both cached results.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • TkDodo

Poem

🐰 Queries both fresh and stale
Dance through the cache's tale
One refetches with grace
While one stays in its place
Tests verify the whole travail

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a test for the mixed cache state scenario (fresh + stale) in useSuspenseQueries.
Description check ✅ Passed The description covers all required template sections: Changes section explains the test purpose and verifications, Checklist items are completed, and Release Impact is properly marked as dev-only.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/useSuspenseQueries-fresh-stale-mixed-cache

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

@sukvvon sukvvon merged commit 7fc6e6a into main Mar 28, 2026
10 checks passed
@sukvvon sukvvon deleted the test/useSuspenseQueries-fresh-stale-mixed-cache branch March 28, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant