Skip to content

fix(query-persist-client-core): use setTimeout instead of notifyManager.schedule - #12749

Merged
TkDodo merged 2 commits into
mainfrom
schiller-manuel-backport-create-persister-settimeout
Dec 4, 2026
Merged

TkDodo merged 2 commits into
mainfrom
schiller-manuel-backport-create-persister-settimeout

Conversation

@schiller-manuel

@schiller-manuel schiller-manuel commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Changes

Backports the packages/query-persist-client-core/src/createPersister.ts change from #12662 (v6) to v5.

experimental_createQueryPersister needs a macrotask after queryFn resolves so query.setData applies before persisting state or running afterRestoreMacroTask. Previously both callbacks were scheduled via notifyManager.schedule, so configuring a microtask scheduler via notifyManager.setScheduler caused them to run before query.setData, overwriting restored dataUpdatedAt, skipping stale refetches while fetchStatus was still 'fetching', and persisting pending state with data: undefined and dataUpdatedAt: 0.

Replacing both calls with direct setTimeout(..., 0) ensures query state settles first regardless of the configured notifyManager scheduler.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I have followed the AI contribution policy and fully understand the code in this pull request, including any code generated with AI assistance.

🚀 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

  • Bug Fixes
    • Query data is now persisted and restored reliably when a microtask notification scheduler is configured.
    • Restored and fetched query state is applied before persistence and post-restore callbacks run.
    • Restoring cached data without refetching preserves its timestamps; stale data is refreshed and the updated state is persisted.

…er.schedule

Backport the createPersister.ts change from TanStack Query #12662 (v6) to v5.

experimental_createQueryPersister needs a macrotask after queryFn resolves so query.setData applies before persisting state or running afterRestoreMacroTask, even when consumers configure a microtask scheduler via notifyManager.setScheduler.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@changeset-bot

changeset-bot Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0220819

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 26 packages
Name Type
@tanstack/query-persist-client-core Patch
@tanstack/angular-query-persist-client Patch
@tanstack/preact-query-persist-client Patch
@tanstack/preact-query Patch
@tanstack/query-async-storage-persister Patch
@tanstack/query-sync-storage-persister Patch
@tanstack/react-query-persist-client Patch
@tanstack/react-query Patch
@tanstack/solid-query-persist-client Patch
@tanstack/svelte-query-persist-client Patch
@tanstack/angular-query-devtools Patch
@tanstack/angular-query Patch
@tanstack/eslint-plugin-query Patch
@tanstack/preact-query-devtools Patch
@tanstack/query-broadcast-client-experimental Patch
@tanstack/query-core Patch
@tanstack/query-devtools Patch
@tanstack/react-query-devtools Patch
@tanstack/react-query-next-experimental Patch
@tanstack/solid-query-devtools Patch
@tanstack/solid-query Patch
@tanstack/vue-query Patch
@tanstack/svelte-query-devtools Patch
@tanstack/svelte-query Patch
@tanstack/vue-query-devtools Patch
@tanstack/lit-query Patch

Not sure what this means? Click here to learn what changesets are.

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

@nx-cloud

nx-cloud Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 0220819

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

☁️ Nx Cloud last updated this comment at 2026-12-04 20:26:44 UTC

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

3 package(s) bumped directly, 23 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/query-core 5.108.4 → 5.108.5 Changeset
@tanstack/query-devtools 5.108.4 → 5.108.5 Changeset
@tanstack/query-persist-client-core 5.108.4 → 5.108.5 Changeset
@tanstack/angular-query 5.108.4 → 5.108.5 Dependent
@tanstack/angular-query-devtools 5.108.4 → 5.108.5 Dependent
@tanstack/angular-query-persist-client 5.108.4 → 5.108.5 Dependent
@tanstack/eslint-plugin-query 5.108.4 → 5.108.5 Dependent
@tanstack/lit-query 0.2.44 → 0.2.45 Dependent
@tanstack/preact-query 5.108.4 → 5.108.5 Dependent
@tanstack/preact-query-devtools 5.108.4 → 5.108.5 Dependent
@tanstack/preact-query-persist-client 5.108.4 → 5.108.5 Dependent
@tanstack/query-async-storage-persister 5.108.4 → 5.108.5 Dependent
@tanstack/query-broadcast-client-experimental 5.108.4 → 5.108.5 Dependent
@tanstack/query-sync-storage-persister 5.108.4 → 5.108.5 Dependent
@tanstack/react-query 5.108.4 → 5.108.5 Dependent
@tanstack/react-query-devtools 5.108.4 → 5.108.5 Dependent
@tanstack/react-query-next-experimental 5.108.4 → 5.108.5 Dependent
@tanstack/react-query-persist-client 5.108.4 → 5.108.5 Dependent
@tanstack/solid-query 5.108.4 → 5.108.5 Dependent
@tanstack/solid-query-devtools 5.108.4 → 5.108.5 Dependent
@tanstack/solid-query-persist-client 5.108.4 → 5.108.5 Dependent
@tanstack/svelte-query 6.4.7 → 6.4.8 Dependent
@tanstack/svelte-query-devtools 6.4.7 → 6.4.8 Dependent
@tanstack/svelte-query-persist-client 6.4.7 → 6.4.8 Dependent
@tanstack/vue-query 5.108.4 → 5.108.5 Dependent
@tanstack/vue-query-devtools 6.4.7 → 6.4.8 Dependent

@pkg-pr-new

pkg-pr-new Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
More templates

@tanstack/angular-query

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

@tanstack/angular-query-devtools

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

@tanstack/angular-query-persist-client

npm i https://pkg.pr.new/@tanstack/angular-query-persist-client@12749

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 0220819

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 11.97 KB (0%)
react minimal 8.71 KB (0%)

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The persister now defers post-restore callbacks and post-fetch persistence with setTimeout(..., 0) instead of notifyManager.schedule. Tests cover fetch and restore behavior with a microtask notification scheduler.

Changes: Persister scheduling

Layer / File(s) Summary
Deferred restore callbacks and persistence
packages/query-persist-client-core/src/createPersister.ts, packages/query-persist-client-core/src/__tests__/createPersister.test.ts, .changeset/query-persist-client-core-settimeout.md
The persister uses zero-delay timers for post-restore callbacks and post-fetch persistence. Tests check fetched state persistence, restored data and timestamps without refetching, and stale restored data that is refetched and persisted. The changeset records the patch and scheduling change.

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

Change: Bug fix

Suggested reviewers: sukvvon, dogpawhat

Merge Risk: Minimal · up to f1e62

The persister now defers its post-restore callback and post-fetch persistence with zero-delay timers, so restored timestamps and fetched state settle correctly under a microtask scheduler. No merge-blocking risk was identified. The scope is limited to the experimental persister.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the package and the core change: replacing notifyManager.schedule with setTimeout in createPersister. The raw summary and PR objectives confirm both scheduling calls in experimental_cr…
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.
Description check Passed The description explains the change clearly. It backports the createPersister.ts fix from #12662 (v6) to v5. It replaces both notifyManager.schedule calls in experimental_createQueryPersister with set…
Full details: Title check

Explanation

The title names the package and the core change: replacing notifyManager.schedule with setTimeout in createPersister. The raw summary and PR objectives confirm both scheduling calls in experimental_createQueryPersister were replaced. The title is specific, concise, and matches the main change.

Full details: Description check

Explanation

The description explains the change clearly. It backports the createPersister.ts fix from #12662 (v6) to v5. It replaces both notifyManager.schedule calls in experimental_createQueryPersister with setTimeout(..., 0). It also gives the motivation: with a microtask scheduler set through notifyManager.setScheduler, the callbacks ran before query.setData and caused several bugs. The Checklist is filled in, and the author marks the changeset as generated. The template's required sections are all present. The description does not mention the regression tests that the PR objectives describe, but that detail is not a template requirement.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 331f45a and f1e627e.

Files selected for processing: 3

  • .changeset/query-persist-client-core-settimeout.md
  • packages/query-persist-client-core/src/__tests__/createPersister.test.ts
  • packages/query-persist-client-core/src/createPersister.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

…er tests

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@TkDodo
TkDodo merged commit d36ae98 into main Dec 4, 2026
9 checks passed
@TkDodo
TkDodo deleted the schiller-manuel-backport-create-persister-settimeout branch December 4, 2026 21:00
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.

2 participants