Skip to content

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

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

test(react-query/useQuery.promise): unskip 'cancelQueries' while suspending test by keeping 'queryFn' in-flight#10910
sukvvon wants to merge 29 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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2b0e4f4b-58e8-4a19-9bf7-3fbd25cbc43e

📥 Commits

Reviewing files that changed from the base of the PR and between 053a7af and 96b6a5a.

📒 Files selected for processing (1)
  • packages/react-query/src/__tests__/useQuery.promise.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-query/src/tests/useQuery.promise.test.tsx

📝 Walkthrough

Walkthrough

A previously skipped suspension and cancellation test is enabled. Its mocked query function now waits longer before resolving with constant data, preserving the in-flight promise while cancelQueries runs before a later refetch.

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
Enables the cancellation test and changes its mock query function to use sleep(50) and return 'test', with comments explaining fake-timer and render timing.

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

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: unskipping the cancelQueries suspension test by keeping the query in flight.
Description check ✅ Passed The description matches the template and includes changes, checklist items, and release impact.
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.
✨ 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/react-query-unskip-cancel-queries-while-suspending

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

@nx-cloud

nx-cloud Bot commented Jun 10, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 26df022

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

☁️ Nx Cloud last updated this comment at 2026-07-28 05:00:00 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: 26df022

@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 12.15 KB (0%)
react minimal 9.1 KB (0%)

@sukvvon
sukvvon marked this pull request as draft June 10, 2026 12:24
sukvvon added 21 commits June 11, 2026 10:21
@sukvvon
sukvvon marked this pull request as ready for review July 26, 2026 17:07
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