Skip to content

fix(svelte-query): handle shrinking createRawRef array by multiple entries (#10341)#10892

Open
ousamabenyounes wants to merge 1 commit into
TanStack:mainfrom
ousamabenyounes:fix/issue-10341
Open

fix(svelte-query): handle shrinking createRawRef array by multiple entries (#10341)#10892
ousamabenyounes wants to merge 1 commit into
TanStack:mainfrom
ousamabenyounes:fix/issue-10341

Conversation

@ousamabenyounes
Copy link
Copy Markdown
Contributor

@ousamabenyounes ousamabenyounes commented Jun 6, 2026

Summary

Fix #10341

createQueries crashed with TypeError: 'deleteProperty' on proxy: trap returned falsish for property 'N' whenever two or more items were removed from its reactive array in a single update. The crash bubbled up from the $effect.pre in createQueries.svelte.ts, but the root cause sits in createRawRef (packages/svelte-query/src/containers.svelte.ts).

Root cause

createRawRef.update() iterates keysToRemove in ascending index order. For arrays, the deleteProperty trap decrements target.length on every successful delete — so after the first deletion the next stale index is no longer in target, the trap returns false, and delete throws in strict mode (ES modules). The trap was also returning false when the property was already absent, which is not how delete is meant to behave on a missing prop.

Fix

Two small, related changes in packages/svelte-query/src/containers.svelte.ts:

  1. Sort keysToRemove numerically descending when newValue is an array, so every delete acts on the current tail and length-- stays valid.
  2. Return true from deleteProperty for missing props — the spec semantic for delete on an absent property is a no-op, not a strict-mode throw. This makes the trap robust against any other path that might also try to delete a stale index.

Both are needed: (1) is the correctness fix; (2) is defense in depth that makes the trap behave like a normal object trap.

Verification

  • Added regression test should handle shrinking an array by more than one entry at once in packages/svelte-query/tests/containers.svelte.test.ts — shrinks [1, 2, 3, 4, 5][1, 2][1, 2, 3, 4][].
  • Test fails on main with the exact symptom from the issue:
    TypeError: 'deleteProperty' on proxy: trap returned falsish for property '4' at src/containers.svelte.ts:93.
  • Test passes with the patch applied.
  • Full @tanstack/svelte-query:test:lib22 files, 164 tests, all pass.
  • test:eslint and test:types clean.

Changeset

@tanstack/svelte-query: patch — runtime bug fix, no public API change.

Generated by Ora Studio
Vibe coded by ousamabenyounes

Summary by CodeRabbit

  • Bug Fixes
    • Fixed createQueries crashing with a TypeError when removing multiple items from a reactive array in a single update operation. This resolves instability when managing dynamic collections of queries and performing simultaneous removals, improving overall reliability of query management in Svelte applications.

…tries (TanStack#10341)

The `createRawRef` Proxy used by `createQueries` crashed with
`TypeError: 'deleteProperty' on proxy: trap returned falsish for property 'N'`
whenever the reactive query list was shrunk by two or more items in one update.

Two compounding causes:
1. `update()` iterated `keysToRemove` in ascending index order. The trap
   decrements `target.length` after every deletion, so the next stale index
   was no longer `in target` and the trap returned `false`, which throws in
   strict mode (ES modules).
2. The trap returned `false` for missing props instead of treating delete on
   a nonexistent prop as a spec-compliant no-op.

Fix: sort `keysToRemove` descending for arrays so each delete acts on the
current tail, and return `true` from `deleteProperty` when the prop is
already absent.

Generated by Ora Studio
Vibe coded by ousamabenyounes

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 6, 2026

Worried about impact? Review this PR in Change Stack to explore blast radius before you approve or request changes.

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: d6e46d14-35fc-4212-8390-503aad4a9f06

📥 Commits

Reviewing files that changed from the base of the PR and between ba7fbc4 and 7a1c6ce.

📒 Files selected for processing (3)
  • .changeset/fix-svelte-query-shrink-array.md
  • packages/svelte-query/src/containers.svelte.ts
  • packages/svelte-query/tests/containers.svelte.test.ts

📝 Walkthrough

Walkthrough

Fixed a proxy handler crash in createRawRef where deleting multiple array items during a single reactive update would throw a strict-mode error. The deleteProperty trap now returns true for missing properties, and array removal sorts indices in descending order to maintain correct length state during deletion.

Changes

Array Shrinking Proxy Fix

Layer / File(s) Summary
Proxy deleteProperty and array-safe deletion
packages/svelte-query/src/containers.svelte.ts, packages/svelte-query/tests/containers.svelte.test.ts
The deleteProperty trap returns true for non-existent properties, and update() sorts keysToRemove in descending numeric order when removing array elements. A regression test confirms that createRawRef can shrink arrays by multiple entries in a single update without crashing.
Release notes
.changeset/fix-svelte-query-shrink-array.md
Changeset patch entry documents the fix preventing createQueries crashes when multiple array items are deleted simultaneously.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • TkDodo

Poem

A proxy once trembled with fright,
When arrays shrunk more than one bite,
But now with care sorted,
The deletions comported,
🐰 Your queries dance through the night! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. 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 specifically describes the primary fix: handling the shrinking of createRawRef arrays when multiple entries are removed simultaneously.
Description check ✅ Passed The PR description comprehensively covers the bug summary, root cause analysis, specific fixes, verification steps, and changeset details, aligning well with the template structure.
Linked Issues check ✅ Passed The PR directly addresses issue #10341 by fixing the root cause of the createQueries crash when multiple array items are removed, implementing both the descending sort fix and the deleteProperty trap robustness improvements.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the reported issue: the Proxy deleteProperty trap, array shrinking logic, regression test, and changeset entry.

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

✨ 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.

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.

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

1 participant