fix(svelte-query): shrink useMutationState results - #11153
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthrough
ChangesMutation filter result updates
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized fix makes the returned mutation-state array correctly shrink when entries stop matching, while preserving the existing array reference. No actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Yeah. This checks out. Thanks for the commit! |
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
View your CI Pipeline Execution ↗ for commit 9b20de9
☁️ Nx Cloud last updated this comment at |
Changes
Fixes #11152.
useMutationState()in@tanstack/svelte-queryonly ever grew its returnedarray. The cache-subscription callback updated the underlying
$statearraywith
Object.assign(result, nextResult), butArray.prototype.lengthisnon-enumerable, so
Object.assignnever truncatesresultwhen the newresult set is shorter. Once a mutation stopped matching
filters(settled,was removed/GC'd, or a narrower filter was applied), its stale entry stayed
in the array forever.
Fix: replace the
Object.assignwithresult.splice(0, result.length, ...nextResult),which replaces the array's contents in place — including truncating it —
while preserving the
$statearray's reference identity (required by the rune).Includes a regression test that starts two mutations matching
filters: { status: 'pending' }, lets both settle, and asserts the returnedarray goes back to
[]instead of keeping the two stale"pending"entries.✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
Bug Fixes
useMutationStateso mutations are removed from filtered results when they no longer match the selected criteria.Tests