Skip to content

Commit 20dc43c

Browse files
committed
fix(app): make virtua patch bun-compatible
1 parent c4e8640 commit 20dc43c

1 file changed

Lines changed: 44 additions & 42 deletions

File tree

patches/virtua@0.49.1.patch

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
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
116
diff --git a/lib/solid/index.jsx b/lib/solid/index.jsx
2-
index 029201a2c8..e3c4c0ca3a 100644
17+
index 029201a..3949cd4 100644
318
--- a/lib/solid/index.jsx
419
+++ b/lib/solid/index.jsx
520
@@ -1085,6 +1085,7 @@ const createResizer = (store, isHorizontal) => {
@@ -38,54 +53,41 @@ index 029201a2c8..e3c4c0ca3a 100644
3853
$dispose: resizeObserver._dispose,
3954
};
4055
};
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) => {
4266
findItemIndex: store.$findItemIndex,
4367
getItemOffset: store.$getItemOffset,
4468
getItemSize: store.$getItemSize,
4569
+ measure: resizer.$measureItems,
4670
scrollToIndex: scroller.$scrollToIndex,
4771
scrollTo: scroller.$scrollTo,
4872
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);
6580
+ }
81+
+ });
82+
for (let [i, j] = range(); i <= j; i++) {
83+
mounted.add(i);
6684
}
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;
7593
}
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

Comments
 (0)