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

    • Enhanced test coverage to verify that persisted data maintains stability across extended delays.
  • Bug Fixes

    • Refined error handling timing in the persist client to ensure errors are thrown consistently after a short delay, improving reliability of error scenarios.

✏️ 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: ecc6a51

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

A test file for PersistQueryClientProvider has been modified to adjust error handling behavior in an error persister and add additional timer advancement to verify the stability of hydrated state across extended simulated delays.

Changes

Cohort / File(s) Summary
PersistQueryClientProvider Tests
packages/react-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx
Modified error persister to return a promise that resolves after a 10ms delay before throwing, replacing async/await pattern. Added additional timer advancement (11ms) in test assertions to verify hydrated state stability.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify the promise-based error handling pattern correctly replicates the intended timing behavior
  • Confirm additional timer advancement value (11ms) aligns with test intent and doesn't introduce flakiness

Possibly related PRs

Suggested reviewers

  • manudeli

Poem

🐰 A promise delayed by ten small ticks,
Then throws with flairβ€”no async tricks!
Eleven more to check the state,
Hydration holdsβ€”our tests are great!

Pre-merge checks and finishing touches

βœ… Passed checks (3 passed)
Check name Status Explanation
Title check βœ… Passed The title accurately describes the main changes: refactoring async patterns in tests and adding timer verification.
Description check βœ… Passed The description follows the template structure with all required sections completed, including checklist items and release impact assessment.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

πŸ“œ Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

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

πŸ“’ 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
πŸ”‡ Additional comments (2)
packages/react-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx (2)

44-46: LGTM! Aligns with coding style preference.

The change from await sleep(10) followed by throw error to sleep(10).then(() => { throw error }) maintains identical behavior while following the preferred pattern for functions without side effects.

Based on learnings, the .then() pattern is preferred for conciseness when there are no side effects to track.


419-420: LGTM! Improves test robustness.

The additional 11ms timer advance with verification that data remains 'hydrated' strengthens the test by confirming that the hydrated state is stable and no refetch occurs even after sufficient time has passed for a potential refetch to complete. This aligns with the test's intent to verify that staleTime: Infinity prevents refetching.


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 ecc6a51

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

☁️ Nx Cloud last updated this comment at 2025-11-23 17:39:55 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: ecc6a51

@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 (ae47807) to head (ecc6a51).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             main     #9901       +/-   ##
============================================
+ Coverage   45.70%   100.00%   +54.29%     
============================================
  Files         200         1      -199     
  Lines        8437        18     -8419     
  Branches     1936         2     -1934     
============================================
- Hits         3856        18     -3838     
+ Misses       4133         0     -4133     
+ Partials      448         0      -448     
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
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