Skip to content

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Nov 23, 2025

🎯 Changes

βœ… 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 tests to use async/await-style control flow and adjusted simulated timing to verify persisted hydration remains stable across a slightly extended delay, ensuring hydration and subsequent fetch behavior are consistently validated.

✏️ Tip: You can customize this high-level summary in your review settings.

…'await sleep' with 'sleep().then()' pattern in restoreClient and add additional timer advance for refetch verification
@changeset-bot
Copy link

changeset-bot bot commented Nov 23, 2025

⚠️ No Changeset found

Latest commit: fb4071e

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 Nov 23, 2025

Walkthrough

Test updates in PersistQueryClientProvider.test.tsx: query function implementations were rewritten to use async/await (previously used promise chains), and tests advance timers an additional 11ms to assert hydration state remains stable after the longer simulated delay.

Changes

Cohort / File(s) Summary
PersistQueryClientProvider Tests
packages/react-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx
Rewrote queryFn implementations from promise .then() chains to async/await with an await sleep(10) before producing values; added an extra 11ms timer advance in tests and updated assertions to verify hydration state remains stable after the extended delay.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review the rewritten queryFn logic to ensure behavior matches prior promise-chain timing.
  • Verify the additional 11ms timer advance doesn't introduce flakiness in related timing-sensitive tests.

Possibly related PRs

Suggested reviewers

  • manudeli

Poem

πŸ‡ I waited ten, then yielded the prize,
Awaited the tick while timers ran wise.
Eleven more beats to prove what we knew β€”
Hydration held steady, the test passed true. πŸ₯•

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
βœ… Passed checks (2 passed)
Check name Status Explanation
Title check βœ… Passed The title accurately describes the main changes: converting callbacks to async/await and adding delayed assertions for test verification in PersistQueryClientProvider tests.
Description check βœ… Passed The description follows the template structure with completed checklist items and correctly identifies the change as dev-only with no release impact, though the 'Changes' section lacks detail.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ 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 Nov 23, 2025

View your CI Pipeline Execution β†— for commit fb4071e

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... βœ… Succeeded 50s View β†—
nx run-many --target=build --exclude=examples/*... βœ… Succeeded 1s View β†—

☁️ Nx Cloud last updated this comment at 2025-12-19 01:56:11 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 23, 2025

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: fb4071e

@codecov
Copy link

codecov bot commented Nov 23, 2025

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 100.00%. Comparing base (f15b7fc) to head (fb4071e).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             main     #9901       +/-   ##
============================================
+ Coverage   45.89%   100.00%   +54.10%     
============================================
  Files         200         1      -199     
  Lines        8437        18     -8419     
  Branches     1943         2     -1941     
============================================
- Hits         3872        18     -3854     
+ Misses       4116         0     -4116     
+ Partials      449         0      -449     
Components Coverage Ξ”
@tanstack/angular-query-experimental βˆ… <ΓΈ> (βˆ…)
@tanstack/eslint-plugin-query βˆ… <ΓΈ> (βˆ…)
@tanstack/query-async-storage-persister βˆ… <ΓΈ> (βˆ…)
@tanstack/query-broadcast-client-experimental βˆ… <ΓΈ> (βˆ…)
@tanstack/query-codemods βˆ… <ΓΈ> (βˆ…)
@tanstack/query-core βˆ… <ΓΈ> (βˆ…)
@tanstack/query-devtools βˆ… <ΓΈ> (βˆ…)
@tanstack/query-persist-client-core βˆ… <ΓΈ> (βˆ…)
@tanstack/query-sync-storage-persister βˆ… <ΓΈ> (βˆ…)
@tanstack/query-test-utils βˆ… <ΓΈ> (βˆ…)
@tanstack/react-query βˆ… <ΓΈ> (βˆ…)
@tanstack/react-query-devtools βˆ… <ΓΈ> (βˆ…)
@tanstack/react-query-next-experimental βˆ… <ΓΈ> (βˆ…)
@tanstack/react-query-persist-client 100.00% <ΓΈ> (ΓΈ)
@tanstack/solid-query βˆ… <ΓΈ> (βˆ…)
@tanstack/solid-query-devtools βˆ… <ΓΈ> (βˆ…)
@tanstack/solid-query-persist-client βˆ… <ΓΈ> (βˆ…)
@tanstack/svelte-query βˆ… <ΓΈ> (βˆ…)
@tanstack/svelte-query-devtools βˆ… <ΓΈ> (βˆ…)
@tanstack/svelte-query-persist-client βˆ… <ΓΈ> (βˆ…)
@tanstack/vue-query βˆ… <ΓΈ> (βˆ…)
@tanstack/vue-query-devtools βˆ… <ΓΈ> (βˆ…)
πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sukvvon sukvvon marked this pull request as ready for review November 23, 2025 17:40
Comment on lines 44 to 46
await sleep(10)
throw error
return sleep(10).then(() => {
throw error
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question: why? are there any functional difference ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TkDodo If we apply the pattern from #9900 (comment), we could write it like this:

return sleep(10).then(() => Promise.reject(error))

What do you think about this approach?

@sukvvon sukvvon requested a review from TkDodo November 30, 2025 10:50
… convert complex 'then' callbacks to async/await pattern
@sukvvon sukvvon changed the title test(react-query-persist-client/PersistQueryClientProvider): replace 'await sleep' with 'sleep().then()' pattern in restoreClient and add additional timer advance for refetch verification test(react-query-persist-client/PersistQueryClientProvider): convert complex 'then' callback to async/await and add delayed assertion for refetch verification Dec 17, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/react-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx (1)

43-46: Consider .then() pattern for consistency.

For consistency with the established pattern (per learnings: prefer .then() when there are no side effects), consider refactoring this to:

      async restoreClient() {
-       await sleep(10)
-       throw error
+       return sleep(10).then(() => Promise.reject(error))
      },

This matches the suggestion from the past review comments and aligns with the .then() pattern used in createMockPersister (line 25).

πŸ“œ Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between ecc6a51 and 94c1dc9.

πŸ“’ Files selected for processing (1)
  • packages/react-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
πŸ““ Common learnings
Learnt from: sukvvon
Repo: TanStack/query PR: 9892
File: packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx:331-335
Timestamp: 2025-11-22T09:06:05.219Z
Learning: In TanStack/query test files, when a queryFn contains side effects (e.g., setting flags for test verification), prefer async/await syntax for clarity; when there are no side effects, prefer the .then() pattern for conciseness.
πŸ“š Learning: 2025-11-22T09:06:05.219Z
Learnt from: sukvvon
Repo: TanStack/query PR: 9892
File: packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx:331-335
Timestamp: 2025-11-22T09:06:05.219Z
Learning: In TanStack/query test files, when a queryFn contains side effects (e.g., setting flags for test verification), prefer async/await syntax for clarity; when there are no side effects, prefer the .then() pattern for conciseness.

Applied to files:

  • packages/react-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test
  • GitHub Check: Preview
πŸ”‡ Additional comments (1)
packages/react-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx (1)

417-418: LGTM! Improved test coverage.

The additional timer advance verifies that the hydration state remains stable and no refetch occurs when data is fresh, which strengthens the test assertions.

Comment on lines +387 to +391
queryFn: async () => {
await sleep(10)
fetched = true
return 'fetched'
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟑 Minor

Inconsistent PR description, but changes align with learnings.

The PR title and description claim to "replace 'await sleep' with 'sleep().then()' pattern in restoreClient", but the actual change here is in a queryFn and goes in the opposite direction (from .then() to async/await).

However, the change itself is appropriate: the queryFn has a side effect (fetched = true), so async/await syntax is preferred for clarity.

Based on learnings, please update the PR title and description to accurately reflect the actual changes.

πŸ€– Prompt for AI Agents
In
packages/react-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx
around lines 387 to 391, the PR title/description incorrectly state "replace
'await sleep' with 'sleep().then()' pattern in restoreClient" while the actual
change in this test replaces a .then() style sleep with an async/await queryFn
(which is correct due to the side effect). Update the PR title and description
to accurately describe the change (e.g., "use async/await in queryFn with side
effect in PersistQueryClientProvider tests" or similar) and remove any
references to modifying restoreClient or switching to .then() so they match the
code changes.

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.

2 participants