perf(components): [virtual-list] wrap row with Fragment and set key on it (#8284)

fix(components): [virtual-list] wrap row with Fragment and set key on it

closed #8279

Co-authored-by: qiang <qw13131wang@gmail.com>
This commit is contained in:
tkitesy
2024-08-21 10:52:12 +08:00
committed by GitHub
parent b600da6b58
commit bd95cc8a46
2 changed files with 26 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
// @ts-nocheck
import {
Fragment,
computed,
defineComponent,
getCurrentInstance,
@@ -595,17 +596,21 @@ const createGrid = ({
if (totalRow > 0 && totalColumn > 0) {
for (let row = rowStart; row <= rowEnd; row++) {
for (let column = columnStart; column <= columnEnd; column++) {
const key = itemKey({ columnIndex: column, data, rowIndex: row })
children.push(
slots.default?.({
columnIndex: column,
data,
key: itemKey({ columnIndex: column, data, rowIndex: row }),
isScrolling: useIsScrolling
? unref(states).isScrolling
: undefined,
style: getItemStyle(row, column),
rowIndex: row,
})
h(
Fragment,
{ key },
slots.default?.({
columnIndex: column,
data,
isScrolling: useIsScrolling
? unref(states).isScrolling
: undefined,
style: getItemStyle(row, column),
rowIndex: row,
})
)
)
}
}

View File

@@ -1,5 +1,6 @@
// @ts-nocheck
import {
Fragment,
computed,
defineComponent,
getCurrentInstance,
@@ -484,13 +485,16 @@ const createList = ({
if (total > 0) {
for (let i = start; i <= end; i++) {
children.push(
($slots.default as Slot)?.({
data,
key: i,
index: i,
isScrolling: useIsScrolling ? states.isScrolling : undefined,
style: getItemStyle(i),
})
h(
Fragment,
{ key: i },
($slots.default as Slot)?.({
data,
index: i,
isScrolling: useIsScrolling ? states.isScrolling : undefined,
style: getItemStyle(i),
})
)
)
}
}