Skip to content
Source
Sign inSign up
TanStack/query

fix(query-devtools): wrap query cache clear in 'batch' to update the list once instead of once per removed query #12699

Mergedsukvvon(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/12699/headmerged by sukvvon(GitHub profile, opens in a new tab) View on GitHub

sukvvon(GitHub profile, opens in a new tab)commented

🎯 Changes

  • Wrap query_cache().clear() in Solid's batch in the clear cache button handler. QueryCache.clear() removes queries one by one and emits a removed event for each, and the query cache subscription only batches within a single event, so the query list was recomputed and re-rendered once per removed query. With batch, the list updates once after the cache is cleared.
  • Add a test that clears 1000 queries and checks that the list content's style changes once. Without the fix it changes 1000 times.

Measured in Chromium with a production build of examples/react/simple (using @tanstack/react-query-devtools/production), timing the synchronous click on the clear cache button, 3 runs each:

QueriesBeforeAfter
25045–50ms~2ms
1000193–213ms11–12ms
2000503–523ms22–37ms

✅ 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
    • Clearing the query cache now updates the query list once, regardless of how many queries are removed.

Sign in to join this conversation.