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

@ousamabenyounes ousamabenyounes commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

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
    • Resolved a crash in createQueries that could throw a TypeError when multiple items were removed from a reactive array within a single update, improving stability for dynamic query collections.
    • Improved reactive array shrinking behavior so truncation/removals occur reliably when several elements are removed at once.
  • Tests
    • Added a regression test covering multi-step reactive array shrinking to prevent reintroducing the proxy-related failure.

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

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: 7ce26e66-a928-4579-ae92-3a01e810c391

📥 Commits

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

📒 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
✅ Files skipped from review due to trivial changes (1)
  • .changeset/fix-svelte-query-shrink-array.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/svelte-query/tests/containers.svelte.test.ts

📝 Walkthrough

Walkthrough

Updated createRawRef to delete removed array indices from the tail toward the head, preventing proxy deletion failures during multi-item reactive array shrinking. Added regression coverage and a patch changeset.

Changes

Array Shrinking Proxy Fix

Layer / File(s) Summary
Proxy-safe array deletion and regression coverage
packages/svelte-query/src/containers.svelte.ts, packages/svelte-query/tests/containers.svelte.test.ts
update() sorts removed array indices in descending order, and tests verify progressive shrinking of a proxied array, including removal to an empty array.
Release note
.changeset/fix-svelte-query-shrink-array.md
Adds a patch changeset documenting the createQueries array-shrinking crash fix.

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

Possibly related PRs

Suggested reviewers: TkDodo

🚥 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 is concise and accurately summarizes the main fix for shrinking svelte-query arrays.
Description check ✅ Passed The description covers the bug, root cause, fix, verification, and changeset, which is mostly aligned with the template.
Linked Issues check ✅ Passed The patch addresses #10341 by deleting array indices in descending order and adding a regression test for multi-item shrinks.
Out of Scope Changes check ✅ Passed The changeset and regression test are directly tied to the array-shrink bug fix and no unrelated changes are evident.
✨ 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.

@nx-cloud

nx-cloud Bot commented Jun 11, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 7a1c6ce

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

☁️ Nx Cloud last updated this comment at 2026-06-11 00:39:23 UTC

@pkg-pr-new

pkg-pr-new Bot commented Jun 11, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@10892

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10892

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 7a1c6ce

@risalfajar

Copy link
Copy Markdown

Please merge this, this bug is making tanstack query svelte unusable

…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>
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

2 participants