Skip to content

Conversation

DamianOsipiuk
Copy link
Contributor

@DamianOsipiuk DamianOsipiuk commented Oct 10, 2025

🎯 Changes

experimental persister now allows to restore null values

Fixes: #9658

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm 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

  • Bug Fixes
    • Restores persisted data correctly when the value is null, preventing unnecessary refetches.
    • Improves consistency of persistence behavior across sessions with no changes to the public API.

Copy link

changeset-bot bot commented Oct 10, 2025

🦋 Changeset detected

Latest commit: c9443b3

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

This PR includes changesets to release 7 packages
Name Type
@tanstack/query-persist-client-core Patch
@tanstack/angular-query-persist-client Patch
@tanstack/query-async-storage-persister Patch
@tanstack/query-sync-storage-persister Patch
@tanstack/react-query-persist-client Patch
@tanstack/solid-query-persist-client Patch
@tanstack/svelte-query-persist-client 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

Copy link
Contributor

coderabbitai bot commented Oct 10, 2025

Walkthrough

Introduces a changeset for a patch release and modifies createPersister restoration logic to treat undefined distinctly from null. Restoration now occurs when data is not undefined, allowing null to be a valid restored value rather than triggering a refetch.

Changes

Cohort / File(s) Summary of Changes
Release metadata
\.changeset/tender-cameras-brush.md
Added a changeset entry for a patch release of @tanstack/query-persist-client-core, noting restoration of null values.
Persister restoration logic
packages/query-persist-client-core/src/createPersister.ts
Changed restoration check from “not nullish” to “not undefined”. Now treats null as a valid restored value and skips refetch; previously null would not be restored and would proceed to fetch.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App
  participant Persister as createPersister
  participant Storage

  App->>Persister: restore()
  Persister->>Storage: read()
  Storage-->>Persister: restoredData
  alt restoredData !== undefined
    note right of Persister: New behavior: null is valid
    Persister-->>App: return restoredData (may be null)
  else restoredData is undefined
    Persister->>Storage: fetch and persist fallback
    Persister-->>App: return fetched data
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

I nuzzle the cache where bytes softly dwell,
A whisper of null—now honored, held well.
No scurry to fetch, no network to roam,
I twitch my nose: “restored,” we’re home.
Patch-sized hop, precise and small—
Carrots, commits, and correctness for all. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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 succinctly covers the primary change by indicating that the query-persist-client-core persister now allows restoring null values, using conventional scope tags and a clear verb to describe the fix.
Description Check ✅ Passed The pull request description follows the repository template by including the required 🎯 Changes, ✅ Checklist, and 🚀 Release Impact sections, clearly describes the change and its motivation, references the related issue, and shows completed checkboxes where applicable.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch do/allow-restoring-null-values

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

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

Copy link

nx-cloud bot commented Oct 10, 2025

View your CI Pipeline Execution ↗ for commit c9443b3

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

☁️ Nx Cloud last updated this comment at 2025-10-10 21:17:20 UTC

Copy link

pkg-pr-new bot commented Oct 10, 2025

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: c9443b3

Copy link
Contributor

Sizes for commit c9443b3:

Branch Bundle Size
Main
This PR

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: 0

🧹 Nitpick comments (1)
packages/query-persist-client-core/src/createPersister.ts (1)

224-226: Excellent fix for null value restoration.

The change from loose (!=) to strict (!==) equality correctly distinguishes between undefined (no persisted data found, should fetch) and null (explicitly persisted null value, should restore). This semantic distinction aligns with JavaScript conventions.

Consider adding a brief inline comment to clarify the distinction:

+      // Restore if we found persisted data (including explicit null values)
+      // undefined means no data was found, so we should fetch instead
       if (restoredData !== undefined) {
         return Promise.resolve(restoredData as T)
       }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea62def and c9443b3.

📒 Files selected for processing (2)
  • .changeset/tender-cameras-brush.md (1 hunks)
  • packages/query-persist-client-core/src/createPersister.ts (1 hunks)
⏰ 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 (2)
.changeset/tender-cameras-brush.md (1)

1-5: LGTM!

The changeset is properly formatted and clearly describes the change. The patch version bump is appropriate for this behavioral fix in an experimental feature.

packages/query-persist-client-core/src/createPersister.ts (1)

224-226: Verify downstream handling of null query data. Persisted null is now returned (not treated as missing) and won’t trigger refetches—ensure all consuming hooks/components handle null values correctly.

Copy link

codecov bot commented Oct 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.88%. Comparing base (ea62def) to head (c9443b3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9747       +/-   ##
===========================================
+ Coverage   45.53%   80.88%   +35.34%     
===========================================
  Files         196       36      -160     
  Lines        8327      659     -7668     
  Branches     1894      186     -1708     
===========================================
- Hits         3792      533     -3259     
+ Misses       4093      109     -3984     
+ Partials      442       17      -425     
Components Coverage Δ
@tanstack/angular-query-experimental ∅ <ø> (∅)
@tanstack/eslint-plugin-query ∅ <ø> (∅)
@tanstack/query-async-storage-persister 43.85% <ø> (ø)
@tanstack/query-broadcast-client-experimental ∅ <ø> (∅)
@tanstack/query-codemods ∅ <ø> (∅)
@tanstack/query-core ∅ <ø> (∅)
@tanstack/query-devtools ∅ <ø> (∅)
@tanstack/query-persist-client-core 80.00% <100.00%> (ø)
@tanstack/query-sync-storage-persister 84.61% <ø> (ø)
@tanstack/query-test-utils ∅ <ø> (∅)
@tanstack/react-query 96.01% <ø> (ø)
@tanstack/react-query-devtools 10.00% <ø> (ø)
@tanstack/react-query-next-experimental ∅ <ø> (∅)
@tanstack/react-query-persist-client 100.00% <ø> (ø)
@tanstack/solid-query ∅ <ø> (∅)
@tanstack/solid-query-devtools ∅ <ø> (∅)
@tanstack/solid-query-persist-client 100.00% <ø> (ø)
@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.

@DamianOsipiuk DamianOsipiuk merged commit 846d53d into main Oct 10, 2025
9 checks passed
@DamianOsipiuk DamianOsipiuk deleted the do/allow-restoring-null-values branch October 10, 2025 21:18
@github-actions github-actions bot mentioned this pull request Oct 10, 2025
Hellol77 pushed a commit to Hellol77/query that referenced this pull request Oct 14, 2025
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.

[persist-client-core] Query data of value "null" is not restored

1 participant