Skip to content

fix(svelte-query): useMutationState array never shrank when mutations stopped matching filter - #11540

Open
okxint wants to merge 1 commit into
TanStack:mainfrom
okxint:fix/svelte-query-use-mutation-state-shrink
Open

okxint wants to merge 1 commit into
TanStack:mainfrom
okxint:fix/svelte-query-use-mutation-state-shrink

Conversation

@okxint

@okxint okxint commented Sep 18, 2026

Copy link
Copy Markdown

Summary

Object.assign copies enumerable own properties but never sets Array.length. When nextResult was shorter than result (fewer mutations matched the filter), trailing stale entries were never removed — the array only ever grew.

Fix: replace Object.assign(result, nextResult) with result.splice(0, result.length, ...nextResult).

splice keeps the reactive $state array reference intact (required by Svelte 5 runes) while correctly adjusting length, adding, and removing elements in one operation.

Fixes #11152

Changes

  • packages/svelte-query/src/useMutationState.svelte.ts — one-line fix
  • packages/svelte-query/tests/useMutationState/useMutationState.svelte.test.ts — regression test: two pending mutations both settle, assert the filtered result shrinks to []
  • .changeset/fix-svelte-use-mutation-state-shrink.md — patch changeset

Test plan

pnpm --filter @tanstack/svelte-query test

The new test (should remove mutations that no longer match the filter) would have failed before this fix.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed mutation state results so entries are removed when mutations no longer match the active filter.
    • Ensured filtered mutation lists accurately reflect the current mutation status.
  • Tests

    • Added coverage confirming that pending mutation results shrink correctly after mutations settle.

… stopped matching filter

Object.assign copies enumerable own properties but never sets Array.length.
When nextResult was shorter than result (fewer mutations matched the filter),
trailing stale entries were never removed — the array only ever grew.

Fix: replace Object.assign with result.splice(0, result.length, ...nextResult).
splice keeps the reactive $state array reference intact (required by Svelte 5
runes) while correctly adjusting length, adding, and removing elements.

Adds a regression test: two pending mutations, both settle, assert the
filtered result shrinks to [].

Fixes TanStack#11152
@coderabbitai

coderabbitai Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 62472588-b211-48fe-be8f-1c4b34ab9b68

📥 Commits

Reviewing files that changed from the base of the PR and between d346e85 and be3610e.

📒 Files selected for processing (3)
  • .changeset/fix-svelte-use-mutation-state-shrink.md
  • packages/svelte-query/src/useMutationState.svelte.ts
  • packages/svelte-query/tests/useMutationState/useMutationState.svelte.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

useMutationState now updates its reactive array with splice, so entries that no longer match the filter are removed. A regression test verifies the array changes from two pending mutations to an empty array after both mutations settle.

Changes

Mutation state filtering

Layer / File(s) Summary
In-place filtered result update and regression coverage
packages/svelte-query/src/useMutationState.svelte.ts, packages/svelte-query/tests/useMutationState/useMutationState.svelte.test.ts, .changeset/fix-svelte-use-mutation-state-shrink.md
The reactive result array now replaces its contents with the current filtered results. The test verifies that settled mutations are removed, and the changeset records the patch release.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: sukvvon

Merge Risk: ⚪ Minimal · up to be361

The mutation-state result now removes settled mutations while retaining the reactive array reference, with regression coverage for the reported failure. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: preventing the useMutationState result array from retaining stale entries.
Description check ✅ Passed The description clearly explains the defect, fix, affected files, regression test, test command, and changeset. It omits the template's Checklist and Release Impact headings, but the core required inf…
Linked Issues check ✅ Passed For #11152, the cache subscription now uses result.splice(0, result.length, ...nextResult). This preserves the existing array reference and replaces all contents, including removal of stale trailing…
Out of Scope Changes check ✅ Passed The changed source line directly fixes the stale-array behavior in #11152. The added test covers the reported regression. The changeset documents the package fix. No unrelated product behavior or unre…
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

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.

useMutationState never removes mutations that no longer match the filter (svelte-query)

1 participant