Skip to content

Commit 8a624c0

Browse files
committed
fix(JVirtual): check for existence on slot
When changing arrays, given there is a tiny delay caused by the worker, the visibleItems array might not match with the current passed one. Fixes #2624 Signed-off-by: Fernando Fernández <[email protected]>
1 parent 2b6868d commit 8a624c0

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

packages/ui-toolkit/src/components/JVirtual/JVirtual.vue

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@
1111
<slot :item="items[0]" />
1212
</Component>
1313
<template v-if="visibleItems.length">
14-
<JSlot
15-
v-for="internal_item in visibleItems"
16-
:key="indexAsKey ? internal_item.index : undefined"
17-
class="uno-transform-gpu"
18-
:class="gridClass"
19-
:style="internal_item.style">
20-
<slot
21-
:item="items[internal_item.index]"
22-
:index="internal_item.index" />
23-
</JSlot>
14+
<template v-for="internal_item in visibleItems">
15+
<JSlot
16+
v-if="items[internal_item.index]"
17+
:key="indexAsKey ? internal_item.index : undefined"
18+
class="uno-transform-gpu"
19+
:class="gridClass"
20+
:style="internal_item.style">
21+
<slot
22+
:item="items[internal_item.index]"
23+
:index="internal_item.index" />
24+
</JSlot>
25+
</template>
2426
</template>
2527
</Component>
2628
</template>
@@ -262,7 +264,7 @@ const populateCache = (() => {
262264
* We cache the items to avoid the extra overhead of sending the items
263265
* to the worker when scrolling fast. We cache 2 times the buffer length
264266
*/
265-
function populateCache(): void {
267+
return function (): void {
266268
if (!isUndef(resizeMeasurement.value)
267269
&& Number.isFinite(bufferLength.value)
268270
&& Number.isFinite(bufferOffset.value)
@@ -286,9 +288,7 @@ const populateCache = (() => {
286288
void setCache(i);
287289
}
288290
}
289-
}
290-
291-
return populateCache;
291+
};
292292
})();
293293
294294
useEventListener(scrollTargets, 'scroll', () => {

0 commit comments

Comments
 (0)