@@ -129,6 +129,13 @@ export class TreeVirtualScroll {
129
129
130
130
if ( ! this . viewportHeight || ! visibleNodes . length ) return [ ] ;
131
131
132
+ // When loading children async this method is called before their height and position is calculated.
133
+ // In that case firstIndex === 0 and lastIndex === visibleNodes.length - 1 (e.g. 1000),
134
+ // which means that it loops through every visibleNodes item and push them into viewportNodes array.
135
+ // We can prevent nodes from being pushed to the array and wait for the appropriate calculations to take place
136
+ const lastVisibleNode = visibleNodes . slice ( - 1 ) [ 0 ]
137
+ if ( ! lastVisibleNode . height && lastVisibleNode . position === 0 ) return [ ] ;
138
+
132
139
// Search for first node in the viewport using binary search
133
140
// Look for first node that starts after the beginning of the viewport (with buffer)
134
141
// Or that ends after the beginning of the viewport
@@ -145,19 +152,6 @@ export class TreeVirtualScroll {
145
152
146
153
const viewportNodes = [ ] ;
147
154
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
-
161
155
for ( let i = firstIndex ; i <= lastIndex ; i ++ ) {
162
156
viewportNodes . push ( visibleNodes [ i ] ) ;
163
157
}
0 commit comments