Skip to content

test(react-query/useSuspenseQueries): remove unnecessary 'act' from background refetch and post-unmount assertions#10211

Open
sukvvon wants to merge 1 commit intoTanStack:mainfrom
sukvvon:test/react-query-useSuspenseQueries-remove-unnecessary-act
Open

test(react-query/useSuspenseQueries): remove unnecessary 'act' from background refetch and post-unmount assertions#10211
sukvvon wants to merge 1 commit intoTanStack:mainfrom
sukvvon:test/react-query-useSuspenseQueries-remove-unnecessary-act

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Mar 2, 2026

🎯 Changes

Remove unnecessary act() wrapping in useSuspenseQueries tests where no suspend resolution occurs.

act() is only needed when resolving a suspended component (pending → resolved state change). In the following cases, act() is unnecessary:

  • Background refetch after suspend lifts: stale timer fires and refetch completes, but the component is already mounted and rendering normally
  • Post-unmount query resolution and GC: component is unmounted, only queryClient internal state is checked
  • Post-resolve idle time: suspend already resolved, verifying no additional re-renders (infinite loop check)

✅ 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 affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Tests
    • Updated internal test utilities for improved timer control flow in asynchronous test scenarios.

…ackground refetch and post-unmount assertions
@changeset-bot
Copy link

changeset-bot bot commented Mar 2, 2026

⚠️ No Changeset found

Latest commit: 6b8b9cc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a59b2d and 6b8b9cc.

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

📝 Walkthrough

Walkthrough

Removed act(...) wrappers around vi.advanceTimersByTimeAsync(...) calls in the useSuspenseQueries test suite. This simplifies timer control in test execution without altering test structure or assertion logic, affecting only the batching context for asynchronous timer-driven operations.

Changes

Cohort / File(s) Summary
Test Timer Control Simplification
packages/react-query/src/__tests__/useSuspenseQueries.test.tsx
Removed act(...) wrappers around multiple vi.advanceTimersByTimeAsync(...) calls, allowing timer advancement to execute directly in the test execution context.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • TkDodo
  • manudeli

Poem

🐰 With act() unwrapped, the timers now flow,
No extra batching needed—watch the tests go!
Advancing through time, clean and direct,
Simpler assertions, just as we'd expect.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: removing unnecessary 'act' wrappers from useSuspenseQueries tests, specifically for background refetch and post-unmount assertions.
Description check ✅ Passed The description follows the template structure with completed 🎯 Changes section explaining the rationale, all checklist items marked appropriately, and Release Impact correctly marked as dev-only.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@nx-cloud
Copy link

nx-cloud bot commented Mar 2, 2026

View your CI Pipeline Execution ↗ for commit 6b8b9cc

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

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 2, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 01141ea

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