Skip to content

Add removeQueries#10186

Open
rklomp wants to merge 12 commits intoTanStack:mainfrom
rklomp:main
Open

Add removeQueries#10186
rklomp wants to merge 12 commits intoTanStack:mainfrom
rklomp:main

Conversation

@rklomp
Copy link
Contributor

@rklomp rklomp commented Feb 25, 2026

🎯 Changes

This adds a removeQueries method to the experimental_createQueryPersister
See also #9189

✅ 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

  • New Features

    • Added ability to remove persisted queries from storage with optional query-key filters (supports exact and partial matches).
  • Documentation

    • Added API docs describing the new query-removal utility.
  • Tests

    • Added test coverage for query removal (filters, exact/partial matches); a duplicate test suite was unintentionally introduced.
  • Chores

    • Bumped package version to reflect the new public API.

@changeset-bot
Copy link

changeset-bot bot commented Feb 25, 2026

🦋 Changeset detected

Latest commit: afced99

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 25, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a new persister method removeQueries(filters) to the core persister API; it iterates storage entries(), deserializes values with try/catch, and removes stored items matching optional queryKey and exact filters. Restoration logic is hardened to skip/clean invalid entries. Docs, tests, and changeset updated.

Changes

Cohort / File(s) Summary
Documentation
docs/framework/react/plugins/createPersister.md
Added API docs for removeQueries(filters) describing usage, supported queryKey/exact filters, and requirement that storage expose entries(); placed alongside other persister utilities.
Core implementation
packages/query-persist-client-core/src/createPersister.ts
Added exported removeQueries(filters = {}) to the persister return object; iterates storage.entries(), wraps deserialization in try/catch, filters by queryKey/exact, calls storage.removeItem for matches, and throws in development if entries() is missing. Hardened restore path to skip/remove busted or expired entries and apply storageKeyPrefix filtering.
Tests
packages/query-persist-client-core/src/__tests__/createPersister.test.ts
Inserted a second, duplicated describe('removeQueries', ...) block covering removal without filters, by queryKey, partial vs exact matching, and no-match cases (test-suite duplication/reordering).
Release metadata
.changeset/fifty-zebras-stay.md
Bumped package and recorded addition of removeQueries to experimental_createQueryPersister public API.

Sequence Diagram(s)

sequenceDiagram
  participant QC as QueryClient
  participant P as Persister
  participant S as Storage
  QC->>P: removeQueries(filters)
  P->>S: entries()
  loop for each (key, value)
    S-->>P: (key, value)
    P->>P: try deserialize(value)
    alt deserialize OK and matches filters
      P->>S: removeItem(key)
    else deserialize fails or doesn't match
      P->>P: skip entry (maybe remove if expired/busted)
    end
  end
  P-->>QC: Promise resolves
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibble through bytes at dawn's first light,

sniff keys exact or loose in flight,
I skip the rotten, sweep the rest away,
now queries sleep till another day. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 'Add removeQueries' is concise, clear, and directly summarizes the main change: adding a removeQueries method to the experimental_createQueryPersister.
Description check ✅ Passed The PR description follows the required template with all sections filled out: Changes section explains the addition, both checklist items are marked complete, and Release Impact correctly identifies this as published code with a changeset generated.

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

@github-actions github-actions bot added documentation Improvements or additions to documentation package: query-persist-client-core labels Feb 25, 2026
@nx-cloud
Copy link

nx-cloud bot commented Feb 25, 2026

View your CI Pipeline Execution ↗ for commit afced99

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

☁️ Nx Cloud last updated this comment at 2026-02-25 16:12:55 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 25, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: afced99

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

🧹 Nitpick comments (1)
docs/framework/react/plugins/createPersister.md (1)

131-132: Tighten wording for clarity and terminology consistency.

Line 131 should use “persister” and “needs to be removed separately” for clearer English.

Proposed wording cleanup
-When using `queryClient.removeQueries` the data is kept in the persistor and to be removed separately.
+When using `queryClient.removeQueries`, the data remains in the persister and needs to be removed separately.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/framework/react/plugins/createPersister.md` around lines 131 - 132,
Update the sentence that starts with "When using `queryClient.removeQueries`" to
use the term "persister" and the phrase "needs to be removed separately" for
clarity and consistency; specifically replace the current wording so it reads
something like: "When using `queryClient.removeQueries` the data is kept in the
persister and needs to be removed separately. This function can be used to
remove queries that are currently stored by the persister." Ensure both
occurrences of "persistor" (if present) are changed to "persister" and adjust
punctuation as needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/framework/react/plugins/createPersister.md`:
- Around line 129-133: The docs incorrectly show removeQueries(queryClient:
QueryClient, filters) but the real API is removeQueries(filters); update the
documentation for the function signature to remove the QueryClient parameter
(use removeQueries(filters): Promise<void>) and adjust the surrounding
description to explain that the persister's removeQueries accepts only filters
and will remove stored queries accordingly; reference the removeQueries function
name in the docs so readers see the corrected signature.

In `@packages/query-persist-client-core/src/createPersister.ts`:
- Around line 329-331: The dev error message inside removeQueries incorrectly
mentions "Restoration of all stored entries" — update the thrown Error in
createPersister.ts (the branch used by removeQueries) to state that removal of
stored entries is not possible without the storage implementing an `entries`
method/ability to iterate over storage items, keeping the same context and
phrasing but replacing "Restoration" with "Removal" and referencing `entries`.
- Line 325: The call to storage.removeItem(key) inside removeQueries is not
awaited, so async storage implementations may not finish removal before
removeQueries resolves; update the removeQueries function to await the
MaybePromise returned by storage.removeItem(key) (i.e., change
storage.removeItem(key) to await storage.removeItem(key)) so behavior matches
the other awaited removeItem usages in this file (see other calls at lines where
removeItem is awaited) and ensure removeQueries returns only after the removal
completes.

---

Nitpick comments:
In `@docs/framework/react/plugins/createPersister.md`:
- Around line 131-132: Update the sentence that starts with "When using
`queryClient.removeQueries`" to use the term "persister" and the phrase "needs
to be removed separately" for clarity and consistency; specifically replace the
current wording so it reads something like: "When using
`queryClient.removeQueries` the data is kept in the persister and needs to be
removed separately. This function can be used to remove queries that are
currently stored by the persister." Ensure both occurrences of "persistor" (if
present) are changed to "persister" and adjust punctuation as needed.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 807c8a9 and bee09d8.

📒 Files selected for processing (3)
  • docs/framework/react/plugins/createPersister.md
  • packages/query-persist-client-core/src/__tests__/createPersister.test.ts
  • packages/query-persist-client-core/src/createPersister.ts

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 @.changeset/fifty-zebras-stay.md:
- Around line 1-5: The changeset incorrectly marks
'@tanstack/query-persist-client-core' as a major bump even though the only
change is adding an additive method removeQueries to the
experimental_createQueryPersister return value; update the changeset to use a
minor version bump instead of major so this non-breaking addition is released as
a minor version.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bee09d8 and a6d5823.

📒 Files selected for processing (1)
  • .changeset/fifty-zebras-stay.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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 312-326: The loop currently uses key.startsWith(prefix) and calls
deserialize(value) unguarded which can process unrelated keys and throw; narrow
the key filter to only the persisted-query namespace (e.g. require the key to
start with `${prefix}-persisted-query-` or otherwise validate the
persisted-query key format before deserializing) and wrap the per-entry
deserialize call in a try/catch so a bad entry is skipped instead of aborting
the whole loop; only call storage.removeItem(key) for entries that successfully
deserialize and pass the existing queryKey/exact checks (refer to variables key,
prefix, deserialize, persistedQuery, queryKey, exact, partialMatchKey, hashKey,
and storage.removeItem).

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a6d5823 and 4a70aa5.

📒 Files selected for processing (3)
  • .changeset/fifty-zebras-stay.md
  • docs/framework/react/plugins/createPersister.md
  • packages/query-persist-client-core/src/createPersister.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/fifty-zebras-stay.md

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 319-337: The deserialization catch block in removeQueries (use of
deserialize, key, storageKeyPrefix, storage.removeItem) currently just continues
and leaves corrupted entries when no queryKey filter is provided; change the
catch to remove the item when queryKey is not provided: inside the catch for
deserialize(value) check if queryKey is falsy/undefined and call
storage.removeItem(key) before continuing, otherwise keep the existing continue
behavior so filtered removal still skips malformed entries.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6bd21ea and cb85cd9.

📒 Files selected for processing (1)
  • packages/query-persist-client-core/src/createPersister.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation package: query-persist-client-core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant