|
| 1 | +diff --git a/lib/solid/Virtualizer.d.ts b/lib/solid/Virtualizer.d.ts |
| 2 | +index 144dd7f..819aab9 100644 |
| 3 | +--- a/lib/solid/Virtualizer.d.ts |
| 4 | ++++ b/lib/solid/Virtualizer.d.ts |
| 5 | +@@ -38,6 +38,10 @@ export interface VirtualizerHandle { |
| 6 | + * @param index index of item |
| 7 | + */ |
| 8 | + getItemSize(index: number): number; |
| 9 | ++ /** |
| 10 | ++ * Synchronously measure currently mounted items and update cached item sizes. |
| 11 | ++ */ |
| 12 | ++ measure(): void; |
| 13 | + /** |
| 14 | + * Scroll to the item specified by index. |
| 15 | + * @param index index of item |
1 | 16 | diff --git a/lib/solid/index.jsx b/lib/solid/index.jsx |
2 | | -index 029201a2c8..e3c4c0ca3a 100644 |
| 17 | +index 029201a..3949cd4 100644 |
3 | 18 | --- a/lib/solid/index.jsx |
4 | 19 | +++ b/lib/solid/index.jsx |
5 | 20 | @@ -1085,6 +1085,7 @@ const createResizer = (store, isHorizontal) => { |
@@ -38,54 +53,41 @@ index 029201a2c8..e3c4c0ca3a 100644 |
38 | 53 | $dispose: resizeObserver._dispose, |
39 | 54 | }; |
40 | 55 | }; |
41 | | -@@ -1380,6 +1396,7 @@ const Virtualizer = (props) => { |
| 56 | +@@ -1354,6 +1370,8 @@ const Virtualizer = (props) => { |
| 57 | + const range = createMemo((prev) => { |
| 58 | + stateVersion(); |
| 59 | + const next = store.$getRange(props.bufferSize); |
| 60 | ++ next[0] = Math.max(0, next[0]); |
| 61 | ++ next[1] = Math.min(props.data.length - 1, next[1]); |
| 62 | + if (prev && isSameRange(prev, next)) { |
| 63 | + return prev; |
| 64 | + } |
| 65 | +@@ -1380,6 +1398,7 @@ const Virtualizer = (props) => { |
42 | 66 | findItemIndex: store.$findItemIndex, |
43 | 67 | getItemOffset: store.$getItemOffset, |
44 | 68 | getItemSize: store.$getItemSize, |
45 | 69 | + measure: resizer.$measureItems, |
46 | 70 | scrollToIndex: scroller.$scrollToIndex, |
47 | 71 | scrollTo: scroller.$scrollTo, |
48 | 72 | scrollBy: scroller.$scrollBy, |
49 | | -@@ -1423,5 +1440,7 @@ const Virtualizer = (props) => { |
50 | | - } |
51 | | - sort([...mounted]).forEach((index) => { |
52 | | -+ if (index < 0 || index >= count) |
53 | | -+ return; |
54 | | - items.push(props.data[index]); |
55 | | - indexes.push(index); |
56 | | - }); |
57 | | -@@ -1430,5 +1449,7 @@ const Virtualizer = (props) => { |
58 | | - else { |
59 | | - for (let [i, j] = range(); i <= j; i++) { |
60 | | -- items.push(props.data[i]); |
61 | | -- indexes.push(i); |
62 | | -+ if (i >= 0 && i < count) { |
63 | | -+ items.push(props.data[i]); |
64 | | -+ indexes.push(i); |
| 73 | +@@ -1417,6 +1436,11 @@ const Virtualizer = (props) => { |
| 74 | + const indexes = []; |
| 75 | + if (props.keepMounted) { |
| 76 | + const mounted = new Set(props.keepMounted); |
| 77 | ++ mounted.forEach((index) => { |
| 78 | ++ if (index < 0 || index >= count) { |
| 79 | ++ mounted.delete(index); |
65 | 80 | + } |
| 81 | ++ }); |
| 82 | + for (let [i, j] = range(); i <= j; i++) { |
| 83 | + mounted.add(i); |
66 | 84 | } |
67 | | -@@ -1579,6 +1600,8 @@ const VList = (props) => { |
68 | | - }); |
69 | | - const items = []; |
70 | | - for (let [i, j] = range(); i <= j; i++) { |
71 | | -- items.push(props.data[i]); |
72 | | -+ if (i >= 0 && i < count) { |
73 | | -+ items.push(props.data[i]); |
74 | | -+ } |
| 85 | +@@ -1528,6 +1552,8 @@ const WindowVirtualizer = (props) => { |
| 86 | + const range = createMemo((prev) => { |
| 87 | + stateVersion(); |
| 88 | + const next = store.$getRange(props.bufferSize); |
| 89 | ++ next[0] = Math.max(0, next[0]); |
| 90 | ++ next[1] = Math.min(props.data.length - 1, next[1]); |
| 91 | + if (prev && isSameRange(prev, next)) { |
| 92 | + return prev; |
75 | 93 | } |
76 | | - return items; |
77 | | -diff --git a/lib/solid/Virtualizer.d.ts b/lib/solid/Virtualizer.d.ts |
78 | | -index 144dd7fba8..819aab92c5 100644 |
79 | | ---- a/lib/solid/Virtualizer.d.ts |
80 | | -+++ b/lib/solid/Virtualizer.d.ts |
81 | | -@@ -38,6 +38,10 @@ export interface VirtualizerHandle { |
82 | | - * @param index index of item |
83 | | - */ |
84 | | - getItemSize(index: number): number; |
85 | | -+ /** |
86 | | -+ * Synchronously measure currently mounted items and update cached item sizes. |
87 | | -+ */ |
88 | | -+ measure(): void; |
89 | | - /** |
90 | | - * Scroll to the item specified by index. |
91 | | - * @param index index of item |
|
0 commit comments