Skip to content

Commit e4767f9

Browse files
committed
fix: ensure proxied arrays correctly update their length upon deletions
1 parent 6776947 commit e4767f9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

.changeset/pink-shirts-film.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure proxied arrays correctly update their length upon deletions

packages/svelte/src/internal/client/proxy.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ export function proxy(value, parent = null, prev) {
104104
sources.set(prop, source(UNINITIALIZED));
105105
}
106106
} else {
107+
// When working with arrays, we need to also ensure we update the length when removing
108+
// an indexed property
109+
if (is_proxied_array && typeof prop === 'string') {
110+
var ls = /** @type {Source<number>} */ (sources.get('length'));
111+
var n = Number(prop);
112+
113+
if (Number.isInteger(n) && n < ls.v) {
114+
set(ls, n);
115+
}
116+
}
107117
set(s, UNINITIALIZED);
108118
update_version(version);
109119
}

0 commit comments

Comments
 (0)