Skip to content

fix(svelte-query): avoid proxy delete failures when queries shrink#10343

Closed
raashish1601 wants to merge 1 commit intoTanStack:mainfrom
raashish1601:contributor-12/query-10341
Closed

fix(svelte-query): avoid proxy delete failures when queries shrink#10343
raashish1601 wants to merge 1 commit intoTanStack:mainfrom
raashish1601:contributor-12/query-10341

Conversation

@raashish1601
Copy link
Copy Markdown

@raashish1601 raashish1601 commented Mar 27, 2026

Summary

  • remove stale array indices from the end first so shrinking query arrays do not trip the proxy delete trap
  • add a low-level createRawRef regression for removing multiple array items in one update
  • add a createQueries regression covering simultaneous removal of multiple Svelte queries

Testing

  • corepack pnpm --filter @tanstack/svelte-query exec vitest run tests/createQueries.svelte.test.ts tests/containers.svelte.test.ts

Closes #10341

Summary by CodeRabbit

Bug Fixes

  • Fixed array element removal to properly handle deletion of multiple trailing elements in ref updates.

Tests

  • Added test coverage verifying array refs correctly shrink when updated to shorter arrays.
  • Added test case for reactive query array mutations and subsequent query removal.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d93da4f6-3412-4b89-8949-8ba94ce057eb

📥 Commits

Reviewing files that changed from the base of the PR and between 1047cdc and f9d78d6.

📒 Files selected for processing (3)
  • packages/svelte-query/src/containers.svelte.ts
  • packages/svelte-query/tests/containers.svelte.test.ts
  • packages/svelte-query/tests/createQueries.svelte.test.ts

📝 Walkthrough

Walkthrough

Fixed a crash in createQueries when removing multiple array elements simultaneously by sorting array indices in descending order before deletion. Added test coverage verifying the fix works for both createRawRef and createQueries with reactive array mutations.

Changes

Cohort / File(s) Summary
Implementation
packages/svelte-query/src/containers.svelte.ts
Modified createRawRef's update function to sort keysToRemove in descending numeric order before deleting array indices, ensuring deletions occur from highest to lowest index.
Test Coverage
packages/svelte-query/tests/containers.svelte.test.ts, packages/svelte-query/tests/createQueries.svelte.test.ts
Added two test cases: one verifying createRawRef correctly removes multiple trailing array elements when replacing with a shorter array, and another verifying createQueries properly shrinks when multiple items are removed from a reactive queryIds array via mutation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Hop-hop, the arrays now delete with care,
From tail to head, no proxy despair!
When queries shrink, they do it right,
No crashes now—just pure delight!

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@raashish1601 raashish1601 deleted the contributor-12/query-10341 branch March 27, 2026 19:52
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.

[svelte-query] createQueries crashes when the several items are removed from the array simultaneously

1 participant