Skip to content

feat(experimental_createQueryPersister): removeItem if deserialize fails#10190

Open
rklomp wants to merge 4 commits intoTanStack:mainfrom
rklomp:deserialize_removeItem
Open

feat(experimental_createQueryPersister): removeItem if deserialize fails#10190
rklomp wants to merge 4 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.
    • Restoration and cleanup now skip problematic entries so overall query recovery is more stable and reliable.

@changeset-bot
Copy link

changeset-bot bot commented Feb 26, 2026

🦋 Changeset detected

Latest commit: 6e20934

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 Minor
@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 6e20934

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

☁️ Nx Cloud last updated this comment at 2026-02-26 09:56: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 8da1d1d and 6e20934.

📒 Files selected for processing (1)
  • packages/query-persist-client-core/src/createPersister.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/query-persist-client-core/src/createPersister.ts

📝 Walkthrough

Walkthrough

A changeset adds a minor release note for @tanstack/query-persist-client-core. createPersister.ts now wraps deserialize calls in try/catch and removes corrupted storage items when deserialization fails to avoid repeated errors.

Changes

Cohort / File(s) Summary
Changeset
.changeset/hungry-adults-count.md
Adds a minor release note for @tanstack/query-persist-client-core with the note "removeItem if deserialize fails".
Persister Error Handling
packages/query-persist-client-core/src/createPersister.ts
Wraps deserialize calls in try/catch within retrieveQuery, persisterGc, and restoreQueries. On deserialization failure the storage key is removed; replaces key-prefix checks with a storageKeyPrefix prefix (prefix + "-"). Iteration continues after removal.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Hopping through keys with a careful shove,

If JSON stumbles, I nudge and remove,
Tidying storage, one item at a time,
Clean retries bounce back in rhyme,
A little rabbit patch — small and kind.

🚥 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 reflects the main change: adding defensive removal of storage items when deserialization fails in the query persister.
Description check ✅ Passed The pull request description follows the required template with all sections completed, including a clear explanation of changes, completed checklist items, and confirmation of 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: 6e20934

@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

@@ -0,0 +1,5 @@
---
'@tanstack/query-persist-client-core': minor
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a patch change

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