Skip to content

fix(query-devtools): coalesce query cache events per microtask to update the list once on 'clear' and 'removeQueries' - #12706

Open
sukvvon wants to merge 3 commits into
mainfrom
fix/query-devtools-coalesce-query-cache-events
Open

sukvvon wants to merge 3 commits into
mainfrom
fix/query-devtools-coalesce-query-cache-events

Conversation

@sukvvon

@sukvvon sukvvon commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

🎯 Changes

  • Coalesce query cache events in setupQueryCacheSubscription. Each event queues the matching subscription updates by subscription id, and a single microtask runs them all inside one Solid batch. queryClient.clear() and queryClient.removeQueries() remove queries one by one and emit a removed event for each, so the query list was recomputed and re-rendered once per removed query when app code called them. Now the list updates once. Every subscription callback reads the cache when it runs, so skipping the intermediate events doesn't change the result.
  • Remove the batch around query_cache().clear() in the clear cache button handler. The coalesced updates already run in one batch, so it no longer does anything.
  • Pass the subscription id to schedule in createCacheSubscriptionRegistry's notify, so repeated updates of the same subscription can be merged.
  • Add tests that call queryClient.clear() with 1000 queries and queryClient.removeQueries() for 500 of them, and check that the list content's style changes once. Without the fix it changes 1000 and 500 times.
  • Await the microtask in existing tests that assert right after a cache change.

Measured in Chromium with a production build of examples/react/simple (using @tanstack/react-query-devtools/production), timing a direct queryClient.clear() / queryClient.removeQueries() call until the devtools update finishes, 3 runs each:

Case Before After
clear(), 250 queries 24–63ms 5–7ms
clear(), 1000 queries 192–214ms 11–13ms
clear(), 2000 queries 508–516ms 14–17ms
removeQueries() half, 1000 queries 135–139ms 5–10ms
removeQueries() half, 2000 queries 330–337ms 7–14ms

✅ 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 Devtools now coalesces cache notifications, helping the query list update once when queries are cleared or removed.
    • Clearing the query cache and removing selected queries now produce consistent list updates.

…ate the list once on 'clear' and 'removeQueries'
@sukvvon sukvvon self-assigned this Nov 26, 2026
@changeset-bot

changeset-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5884b78

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-devtools Patch
@tanstack/angular-query-devtools Patch
@tanstack/preact-query-devtools Patch
@tanstack/react-query-devtools Patch
@tanstack/solid-query-devtools Patch
@tanstack/svelte-query-devtools Patch
@tanstack/vue-query-devtools Patch
@tanstack/angular-query-persist-client Patch
@tanstack/angular-query Patch
@tanstack/eslint-plugin-query Patch
@tanstack/preact-query-persist-client Patch
@tanstack/preact-query Patch
@tanstack/query-async-storage-persister Patch
@tanstack/query-broadcast-client-experimental Patch
@tanstack/query-core Patch
@tanstack/query-persist-client-core Patch
@tanstack/query-sync-storage-persister Patch
@tanstack/react-query-next-experimental Patch
@tanstack/react-query-persist-client Patch
@tanstack/react-query Patch
@tanstack/solid-query-persist-client Patch
@tanstack/solid-query Patch
@tanstack/vue-query Patch
@tanstack/svelte-query-persist-client Patch
@tanstack/svelte-query 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 Nov 26, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 5884b78

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

☁️ Nx Cloud last updated this comment at 2026-11-26 01:34:24 UTC

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

1 package(s) bumped directly, 25 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/query-devtools 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-core 5.108.4 → 5.108.5 Dependent
@tanstack/query-persist-client-core 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

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Query Devtools now coalesces query-cache subscription updates by subscription ID in a microtask and applies them in a batch. Cache clearing no longer adds an outer Solid batch. Tests cover cache clear and removal update counts, along with scheduled updates across Devtools behaviors.

Changes: Query-cache event coalescing

Layer / File(s) Summary
Schedule updates by subscription
packages/query-devtools/src/createCacheSubscriptionRegistry.ts, packages/query-devtools/src/__tests__/createCacheSubscriptionRegistry.test.ts
The registry passes each subscription ID to its scheduler. A test checks that notifications for two subscriptions apply their latest values.
Coalesce Devtools cache updates
packages/query-devtools/src/Devtools.tsx, packages/query-devtools/src/__tests__/Devtools.test.tsx, .changeset/coalesce-devtools-query-cache-events.md
Devtools queues subscription updates by ID and applies them in a batched microtask. Tests verify one observed style mutation for cache clearing and selective query removal, and await scheduled updates in other cases. The changeset declares a patch release.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related PRs

  • TanStack/query#12699: Changes the same clear-cache handler to batch query_cache().clear(); this PR removes that batch and coalesces cache notifications instead.

Suggested reviewers: dogpawhat, tkdodo

Merge Risk: Minimal · up to 5884b

This change coalesces Devtools cache-event updates into one batched update per microtask, so clearing or removing many queries re-renders the list once. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the package (query-devtools), the fix type, and the main change: coalescing query cache events per microtask so the list updates once on 'clear' and 'removeQueries'. This matches the r…
Description check Passed The description follows the template. It has a Changes section that explains the coalescing, the removal of the redundant batch, the subscription ID change, and the new tests, plus timing data. The ch…
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.
Full details: Title check

Explanation

The title names the package (query-devtools), the fix type, and the main change: coalescing query cache events per microtask so the list updates once on 'clear' and 'removeQueries'. This matches the raw summary, which describes the same coalescing of cache events and the single update on clear and removeQueries. The title is long at 117 characters, but it stays on the main change.

Full details: Description check

Explanation

The description follows the template. It has a Changes section that explains the coalescing, the removal of the redundant batch, the subscription ID change, and the new tests, plus timing data. The checklist items are filled in. The contributing checklist marks the test:pr run as unchecked, and the PR objectives confirm that pnpm run test:pr was not marked as run. The Release Impact section has the changeset box checked, which matches the added changeset file.

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 18b1ade and 5884b78.

Files selected for processing: 5

  • .changeset/coalesce-devtools-query-cache-events.md
  • packages/query-devtools/src/Devtools.tsx
  • packages/query-devtools/src/__tests__/Devtools.test.tsx
  • packages/query-devtools/src/__tests__/createCacheSubscriptionRegistry.test.ts
  • packages/query-devtools/src/createCacheSubscriptionRegistry.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.

@pkg-pr-new

pkg-pr-new Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
More templates

@tanstack/angular-query

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

@tanstack/angular-query-devtools

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

@tanstack/angular-query-persist-client

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 5884b78

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

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

This branch has not been deployed

No deployments
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.

1 participant