Skip to content

Commit baa47d2

Browse files
ryansolidmathieuprogcursoragent
committed
fix: preserve zero snapshot array length overrides
Co-authored-by: Mathieu Decaffmeyer <5883963+mathieuprog@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 1251067 commit baa47d2

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/signals": patch
3+
---
4+
5+
Preserve snapshot array length overrides when the overridden length is 0.

packages/solid-signals/src/store/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function snapshotImpl<T>(
4444
map.set(item, item);
4545
}
4646
if (isArray) {
47-
const len = override?.length || item.length;
47+
const len = override?.length ?? item.length;
4848
for (let i = 0; i < len; i++) {
4949
v = override && i in override ? override[i] : item[i];
5050
if (v === $DELETED) continue;

packages/solid-signals/tests/snapshot.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
getOwner,
1111
markSnapshotScope,
1212
releaseSnapshotScope,
13-
setSnapshotCapture
13+
setSnapshotCapture,
14+
snapshot
1415
} from "../src/index.js";
1516

1617
afterEach(() => {
@@ -469,6 +470,14 @@ describe("store snapshot support", () => {
469470
expect($age()).toBe(30);
470471
clearSnapshots();
471472
});
473+
474+
it("preserves an overridden array length of 0", () => {
475+
const [store, setStore] = createStore<number[]>([1, 2, 3]);
476+
477+
setStore(() => []);
478+
479+
expect(snapshot(store)).toEqual([]);
480+
});
472481
});
473482

474483
describe("pending projection skips snapshot capture", () => {

0 commit comments

Comments
 (0)