Skip to content

Commit 71ba8ff

Browse files
committed
Fix: Vertical scrolling causes OffscreenCanvas loss in Grid cells (#8960)
1 parent e15bb38 commit 71ba8ff

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

src/grid/Body.mjs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,19 +1251,37 @@ class GridBody extends Component {
12511251
*
12521252
*/
12531253
updateMountedAndVisibleRows() {
1254-
let me = this,
1255-
{bufferRowRange, startIndex, store} = me,
1256-
countRecords = store.getCount(),
1257-
endIndex = Math.min(countRecords, startIndex + me.availableRows);
1254+
let me = this,
1255+
{bufferRowRange, availableRows, startIndex, store} = me,
1256+
countRecords = store.getCount(),
1257+
windowSize = availableRows + 2 * bufferRowRange,
1258+
endIndex = Math.min(countRecords, startIndex + availableRows),
1259+
mountedStart = startIndex - bufferRowRange,
1260+
mountedEnd = endIndex + bufferRowRange;
12581261

12591262
me.visibleRows[0] = startIndex; // update the array inline
12601263
me.visibleRows[1] = endIndex;
12611264

1262-
startIndex = Math.max(0, startIndex - bufferRowRange);
1263-
endIndex = Math.min(countRecords, endIndex + bufferRowRange);
1265+
// We want to maintain a constant window size (Modulus) to ensure row recycling works
1266+
// via moveNode operations instead of removeNode + insertNode.
1267+
// If we are at the top, extend the end to fill the window.
1268+
if (mountedStart < 0) {
1269+
mountedEnd += Math.abs(mountedStart);
1270+
mountedStart = 0
1271+
}
1272+
1273+
// Clamp to record count
1274+
mountedEnd = Math.min(countRecords, mountedEnd);
1275+
1276+
// If we are at the bottom (hit the ceiling), pull the start back to fill the window.
1277+
// This ensures we keep the DOM nodes alive for as long as possible.
1278+
if (mountedEnd - mountedStart < windowSize) {
1279+
let needed = windowSize - (mountedEnd - mountedStart);
1280+
mountedStart = Math.max(0, mountedStart - needed)
1281+
}
12641282

1265-
me.mountedRows[0] = startIndex; // update the array inline
1266-
me.mountedRows[1] = endIndex
1283+
me.mountedRows[0] = mountedStart; // update the array inline
1284+
me.mountedRows[1] = mountedEnd
12671285
}
12681286

12691287
/**

0 commit comments

Comments
 (0)