Skip to content

test(query-core/queryCache): add test for 'remove' only deleting the instance currently stored under its 'queryHash'#10888

Merged
sukvvon merged 1 commit into
mainfrom
test/query-core-query-cache-remove-stale-query
Jun 5, 2026
Merged

test(query-core/queryCache): add test for 'remove' only deleting the instance currently stored under its 'queryHash'#10888
sukvvon merged 1 commit into
mainfrom
test/query-core-query-cache-remove-stale-query

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Jun 5, 2026

🎯 Changes

Adds a test for QueryCache.remove covering the queryInMap === query guard.

When a stale Query reference is removed after a new instance has taken its place under the same queryHash, remove must only delete the instance currently stored in the cache — not the newer one. The test builds a query, removes it to leave a stale reference, builds a fresh instance with the same key, then removes via the stale reference and asserts queryCache.get(hashKey(key)) still returns the current instance.

✅ 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

This release contains internal improvements with no user-facing changes.

  • Tests
    • Added and improved tests around query cache removal to ensure removing stale instances does not delete the active cached query, increasing cache reliability and preventing regressions.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 5, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5716de68-5ea9-45a1-8c20-3e5223d08f50

📥 Commits

Reviewing files that changed from the base of the PR and between 63c586f and e244afe.

📒 Files selected for processing (1)
  • packages/query-core/src/__tests__/queryCache.test.tsx
✅ Files skipped from review due to trivial changes (1)
  • packages/query-core/src/tests/queryCache.test.tsx

📝 Walkthrough

Walkthrough

This PR adds a test case to the QueryCache test suite verifying that removing a stale query instance does not evict the current query from the cache when both instances share the same queryHash.

Changes

QueryCache remove behavior

Layer / File(s) Summary
QueryCache.remove stale instance test
packages/query-core/src/__tests__/queryCache.test.tsx
Test case constructs two query objects with identical queryHash, removes the stale instance, and confirms the current query remains in the cache under that hash.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Cache cleanup, neat and tidy,
Stale queries go, but keep the spry!
Two hashes, same—the test declares:
One stays, one fades, the QueryCache cares! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the primary change: adding a test for QueryCache.remove that verifies removal only deletes the current cached instance when a stale query with the same queryHash is removed.
Description check ✅ Passed The description fully addresses all required template sections with clear explanations of the change and its motivation, and both checklist items are properly completed with the release impact correctly marked as dev-only.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/query-core-query-cache-remove-stale-query

Comment @coderabbitai help to get the list of available commands and usage tips.

@sukvvon sukvvon self-assigned this Jun 5, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jun 5, 2026

View your CI Pipeline Execution ↗ for commit e244afe

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

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-05 14:54:30 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 5, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: e244afe

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

size-limit report 📦

Path Size
react full 12.11 KB (0%)
react minimal 9.08 KB (0%)

…instance currently stored under its 'queryHash'
@sukvvon sukvvon force-pushed the test/query-core-query-cache-remove-stale-query branch from 63c586f to e244afe Compare June 5, 2026 14:49
@sukvvon sukvvon changed the title test(query-core/queryCache): add test for 'remove' keeping the current query when a stale query with the same 'queryHash' is removed test(query-core/queryCache): add test for 'remove' only deleting the instance currently stored under its 'queryHash' Jun 5, 2026
@sukvvon sukvvon merged commit b63da8a into main Jun 5, 2026
9 checks passed
@sukvvon sukvvon deleted the test/query-core-query-cache-remove-stale-query branch June 5, 2026 15:21
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