Skip to content

test(react-query/useQuery.promise): unskip 'cancelQueries' while suspending test by keeping 'queryFn' in-flight#10910

Draft
sukvvon wants to merge 4 commits into
mainfrom
test/react-query-unskip-cancel-queries-while-suspending
Draft

test(react-query/useQuery.promise): unskip 'cancelQueries' while suspending test by keeping 'queryFn' in-flight#10910
sukvvon wants to merge 4 commits into
mainfrom
test/react-query-unskip-cancel-queries-while-suspending

Conversation

@sukvvon

@sukvvon sukvvon commented Jun 10, 2026

Copy link
Copy Markdown
Member

🎯 Changes

Unskip should stay pending when canceled with cancelQueries while suspending until refetched.

The test was skipped because it had become flaky. With vi.useFakeTimers({ shouldAdvanceTime: true }), awaiting takeRender() advances the shared fake clock by ~35ms while waiting for the React commit. The original sleep(10) queryFn therefore resolved before cancel was clicked, so the query reached success instead of staying in-flight — the "cancel while suspending" scenario could never be exercised.

  • Extend sleep from 10 to 50 so the fetch outlasts the takeRender clock advance and is still in-flight when cancelQueries runs.
  • Switch queryFn to the sleep(...).then(...) form and drop the unused count counter (its return value is never asserted; the test verifies state and a setQueryData value).
  • Add a comment explaining why this sleep is intentionally longer than usual.

✅ 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
    • Re-enabled and updated a test covering query cancellation while suspending until refetched to improve coverage and stability.

Note: This release contains no user-facing changes or new features.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1f5df87a-056d-4f8b-a5b6-99a6291763a1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

A previously skipped test in the useQuery.promise.test.tsx suite is enabled. The test verifies that a query remains in pending status with fetchStatus: 'idle' after being cancelled via cancelQueries while suspending, until a subsequent refetch occurs. The test's query function mock is updated with a longer sleep(50) delay to maintain the promise in-flight across the render stream's timing.

Changes

Test cancellation behavior under suspension

Layer / File(s) Summary
Enable and adjust cancel/suspense test timing
packages/react-query/src/__tests__/useQuery.promise.test.tsx
The previously skipped test for query cancellation during suspension is enabled. The mocked queryFn switches from count-based behavior to a longer sleep(50) duration that resolves to a constant 'test', with added timing comments explaining how the fake timer and render sequence keep the promise in-flight when cancelQueries is called.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • TanStack/query#10903: Both PRs adjust async timing in query test queryFns to make pending/refetch behavior deterministic during promise resolution.

Suggested labels

package: react-query

Poem

A rabbit hops through test and tide,
Wakes a sleeping promise wide,
Cancels call, it stays on hold,
Refetch comes — the tale's retold. 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: unskipping a specific test by keeping the queryFn in-flight, which directly matches the changeset.
Description check ✅ Passed The description is comprehensive, explaining the flakiness root cause, the fix rationale, specific changes, and completing all checklist items including testing and release impact designation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/react-query-unskip-cancel-queries-while-suspending

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

@nx-cloud

nx-cloud Bot commented Jun 10, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 9f788de

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

☁️ Nx Cloud last updated this comment at 2026-06-11 03:15:58 UTC

@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

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

@sukvvon sukvvon self-assigned this Jun 10, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 10, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 9f788de

@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 12.11 KB (0%)
react minimal 9.08 KB (0%)

@sukvvon sukvvon marked this pull request as draft June 10, 2026 12:24
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