Skip to content

Commit 751594d

Browse files
authored
Merge pull request CirclonGroup#696 from jacmgh/fix/issue-463
issue CirclonGroup#463 workaround
2 parents ad70c3b + 3a2003f commit 751594d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/models/tree-virtual-scroll.model.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ export class TreeVirtualScroll {
144144
}, firstIndex);
145145

146146
const viewportNodes = [];
147+
148+
// Loading async top nodes' children is too long.
149+
// It happens when first node is visible withing viewport range (including Y_OFFSET).
150+
// In that case firstIndex == 0 and lastIndex == visibleNodes.length - 1 (e.g. 1000),
151+
// which means that it loops through every visibleNodes item and push them into viewportNodes array.
152+
// lastIndex should not equal visibleNodes.length - 1, but something around 50-100 (depending on the viewport)
153+
const nodeHeight = visibleNodes[0].treeModel.options.options.nodeHeight;
154+
const renderedNodesMaxLength = (Y_OFFSET * 2 + this.viewportHeight) / nodeHeight;
155+
156+
// Something is probably wrong, prevent nodes from being pushed to an array.
157+
if (lastIndex - firstIndex > renderedNodesMaxLength) {
158+
return [];
159+
}
160+
147161
for (let i = firstIndex; i <= lastIndex; i++) {
148162
viewportNodes.push(visibleNodes[i]);
149163
}

0 commit comments

Comments
 (0)