Skip to content

feat(experimental_createQueryPersister): removeItem if deserialize fails#10190

Merged
DamianOsipiuk merged 5 commits intoTanStack:mainfrom
rklomp:deserialize_removeItem
Feb 28, 2026
Merged

feat(experimental_createQueryPersister): removeItem if deserialize fails#10190
DamianOsipiuk merged 5 commits intoTanStack:mainfrom
rklomp:deserialize_removeItem

Conversation

@rklomp
Copy link
Contributor

@rklomp rklomp commented Feb 26, 2026

🎯 Changes

We can remove the item from storage if deserialize fails as its not usable anymore.

✅ 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

  • Bug Fixes
    • Improved resilience of persisted query cache: unreadable or corrupted stored entries are now removed automatically during retrieval, cleanup, and restoration to prevent failures.
    • Retrieval now aborts and clears a problematic stored entry when it cannot be decoded, avoiding stale errors.
    • Cleanup and restoration processes now skip and remove problematic entries so overall recovery is more stable and reliable.

@changeset-bot
Copy link

changeset-bot bot commented Feb 26, 2026

🦋 Changeset detected

Latest commit: 2875eb1

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

@nx-cloud
Copy link

nx-cloud bot commented Feb 26, 2026

View your CI Pipeline Execution ↗ for commit 2875eb1

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

☁️ Nx Cloud last updated this comment at 2026-02-27 18:39:25 UTC

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 26, 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 6e20934 and 2875eb1.

📒 Files selected for processing (1)
  • .changeset/hungry-adults-count.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/hungry-adults-count.md

📝 Walkthrough

Walkthrough

Wraps deserialization in try/catch across persister flows; on deserialize failure the storage entry is removed. Adds a changeset noting the behavior ("removeItem if deserialize fails") for a patch release of @tanstack/query-persist-client-core.

Changes

Cohort / File(s) Summary
Changeset
.changeset/hungry-adults-count.md
Adds a patch release note for @tanstack/query-persist-client-core recording the behavioral change: "removeItem if deserialize fails".
Persister Error Handling
packages/query-persist-client-core/src/createPersister.ts
Wraps deserialize calls in try/catch in retrieveQuery, persisterGc, and restoreQueries; on deserialization failure removes the offending storage key and continues/returns appropriately. Introduces storageKeyPrefix (prefix + "-") and uses startsWith checks for key filtering.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • DamianOsipiuk

Poem

🐇 I nibble at keys where the JSON hides,

If parsing trips, I clear the tides,
One hush of remove, a tiny fix,
Storage hums, no broken bits,
A rabbit’s patch — soft, swift, and wise.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding defensive handling to remove items from storage when deserialization fails in the query persister.
Description check ✅ Passed The description follows the template structure with all required sections completed, including a clear explanation of changes and confirmation of checklist items and changeset generation.

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

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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 26, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: b81831d

@rklomp rklomp changed the title removeItem if deserialize fails feat(experimental_createQueryPersister): removeItem if deserialize fails Feb 26, 2026
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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/query-persist-client-core/src/createPersister.ts`:
- Around line 251-259: The GC loop currently uses key.startsWith(prefix) and may
remove unrelated keys on deserialize failure; update the conditional to match
the delimited prefix used by restoreQueries (use `${prefix}-` or equivalent)
before attempting deserialize and potential storage.removeItem calls so only
intended persisted-query keys (in the entries iteration inside createPersister)
are deserialized and removed; locate the loop over entries, the
key.startsWith(prefix) check, the deserialize(...) call, and
storage.removeItem(...) and tighten the prefix match there.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7d102e and 8da1d1d.

📒 Files selected for processing (2)
  • .changeset/hungry-adults-count.md
  • packages/query-persist-client-core/src/createPersister.ts

@DamianOsipiuk DamianOsipiuk merged commit e505568 into TanStack:main Feb 28, 2026
6 checks passed
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