Skip to content

Commit 10b0b7d

Browse files
committed
refactor: don't use rune for prevScroll/prevProps and fix Svelte warning
1 parent 07db4d6 commit 10b0b7d

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/lib/VirtualList.svelte

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,21 @@
6464
offset: scrollOffset || (scrollToIndex !== undefined && getOffsetForIndex(scrollToIndex)) || 0,
6565
changeReason: SCROLL_CHANGE_REASON.REQUESTED
6666
});
67-
let prevScroll = $state.raw(scroll);
67+
let prevScroll = $state.snapshot(scroll);
6868
6969
let heightNumber = $derived(Number.isFinite(height) ? Number(height) : wrapperHeight);
7070
let widthNumber = $derived(Number.isFinite(width) ? Number(width) : wrapperWidth);
71-
let prevProps = $state.raw({
72-
scrollToIndex,
73-
scrollToAlignment,
74-
scrollOffset,
75-
itemCount,
76-
itemSize,
77-
estimatedItemSize,
78-
heightNumber,
79-
widthNumber,
80-
stickyIndices
81-
});
71+
let prevProps = {
72+
scrollToIndex: $state.snapshot(scrollToIndex),
73+
scrollToAlignment: $state.snapshot(scrollToAlignment),
74+
scrollOffset: $state.snapshot(scrollOffset),
75+
itemCount: $state.snapshot(itemCount),
76+
itemSize: typeof itemSize === 'function' ? itemSize : $state.snapshot(itemSize),
77+
estimatedItemSize: $state.snapshot(estimatedItemSize),
78+
heightNumber: $state.snapshot(heightNumber),
79+
widthNumber: $state.snapshot(widthNumber),
80+
stickyIndices: $state.snapshot(stickyIndices)
81+
};
8282
8383
/** @type {Record<number, string>} */
8484
let styleCache = $state({});
@@ -176,8 +176,7 @@
176176
scrollToAlignment: $state.snapshot(scrollToAlignment),
177177
scrollOffset: $state.snapshot(scrollOffset),
178178
itemCount: $state.snapshot(itemCount),
179-
// @ts-expect-error since snapshot does not support functions properly
180-
itemSize: $state.snapshot(itemSize),
179+
itemSize: typeof itemSize === 'function' ? itemSize : $state.snapshot(itemSize),
181180
estimatedItemSize: $state.snapshot(estimatedItemSize),
182181
heightNumber: $state.snapshot(heightNumber),
183182
widthNumber: $state.snapshot(widthNumber),
@@ -200,7 +199,7 @@
200199
});
201200
}
202201
203-
prevScroll = scroll;
202+
prevScroll = $state.snapshot(scroll);
204203
}
205204
206205
/**

0 commit comments

Comments
 (0)