Skip to content

test(query-core/mutation): add test for 'optionalRemove' when remaining observer exists#10127

Merged
TkDodo merged 3 commits intoTanStack:mainfrom
sukvvon:test/query-core-mutation-optionalRemove-with-remaining-observer
Feb 13, 2026
Merged

test(query-core/mutation): add test for 'optionalRemove' when remaining observer exists#10127
TkDodo merged 3 commits intoTanStack:mainfrom
sukvvon:test/query-core-mutation-optionalRemove-with-remaining-observer

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Feb 13, 2026

🎯 Changes

Add a test case for Mutation.optionalRemove to cover the branch where one observer is removed but another still exists, ensuring the mutation is retained in the cache.

  • When a mutation has two observers and one unsubscribes, scheduleGc is triggered
  • After gcTime elapses, optionalRemove checks this.#observers.length
  • Since one observer still exists, the mutation should NOT be removed from the cache

✅ 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

  • Tests
    • Added test coverage for observer management behavior to ensure mutations persist correctly when multiple observers are active.

@changeset-bot
Copy link

changeset-bot bot commented Feb 13, 2026

⚠️ No Changeset found

Latest commit: a205ed3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

Caution

Review failed

An error occurred during the review process. Please try again later.

📝 Walkthrough

Walkthrough

A new test case is added to verify that unsubscribing one observer from a mutation does not remove the underlying mutation when additional observers remain registered.

Changes

Cohort / File(s) Summary
Test Addition
packages/query-core/src/__tests__/mutations.test.tsx
New test case validating observer lifecycle management—verifies mutation persists in cache when one of multiple observers unsubscribes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

package: query-core

Poem

🐰 A test hopped in with care and grace,
Two observers sharing cache space,
One says goodbye, one stays to see,
The mutation lives, wild and free!

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (9 files):

⚔️ docs/framework/angular/guides/mutation-options.md (content)
⚔️ examples/vue/basic/package.json (content)
⚔️ examples/vue/simple/package.json (content)
⚔️ packages/query-core/src/__tests__/mutations.test.tsx (content)
⚔️ packages/vue-query-devtools/CHANGELOG.md (content)
⚔️ packages/vue-query-devtools/package.json (content)
⚔️ packages/vue-query-devtools/src/types.ts (content)
⚔️ pnpm-lock.yaml (content)
⚔️ tsconfig.json (content)

These conflicts must be resolved before merging into main.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a test for the optionalRemove method when a remaining observer exists.
Description check ✅ Passed The description follows the template structure with all required sections completed: Changes section explains the test case, Checklist items are marked, and Release Impact is specified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

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

@nx-cloud
Copy link

nx-cloud bot commented Feb 13, 2026

View your CI Pipeline Execution ↗ for commit a205ed3

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

☁️ Nx Cloud last updated this comment at 2026-02-13 07:54:15 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 13, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: a205ed3

@TkDodo TkDodo merged commit d7213f7 into TanStack:main Feb 13, 2026
7 checks passed
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