Skip to content

Commit d6dcde3

Browse files
author
Guillaume Chau
committed
Ignore some unnecessary updates + Remove previous items later
This fix issues in complex cases with items changing height multiple times or containing horrible things like iframes
1 parent 8011d8b commit d6dcde3

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

src/components/VirtualScroller.vue

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -286,19 +286,37 @@ export default {
286286
containerHeight = l * itemHeight
287287
}
288288
289-
this.keysEnabled = !(startIndex > this._endIndex || endIndex < this._startIndex)
290-
this._startIndex = startIndex
291-
this._endIndex = endIndex
292-
this._length = l
293-
this.visibleItems = items.slice(startIndex, endIndex)
294-
this.itemContainerStyle = {
295-
height: containerHeight + 'px',
296-
}
297-
this.itemsStyle = {
298-
marginTop: offsetTop + 'px',
299-
}
289+
if (
290+
this._startIndex !== startIndex ||
291+
this._endIndex !== endIndex ||
292+
this._offsetTop !== offsetTop ||
293+
this._height !== containerHeight ||
294+
this._length !== l
295+
) {
296+
this.keysEnabled = !(startIndex > this._endIndex || endIndex < this._startIndex)
297+
298+
// Add next items
299+
this.visibleItems = items.slice(this._startIndex, endIndex)
300+
this.itemContainerStyle = {
301+
height: containerHeight + 'px',
302+
}
303+
this.itemsStyle = {
304+
marginTop: offsetTop + 'px',
305+
}
300306
301-
this.emitUpdate && this.$emit('update', startIndex, endIndex)
307+
// Remove previous items
308+
this.$nextTick(() => {
309+
this.visibleItems = items.slice(startIndex, endIndex)
310+
})
311+
312+
this.emitUpdate && this.$emit('update', startIndex, endIndex)
313+
314+
this._startIndex = startIndex
315+
this._endIndex = endIndex
316+
this._length = l
317+
this._offsetTop = offsetTop
318+
this._height = containerHeight
319+
}
302320
}
303321
},
304322

0 commit comments

Comments
 (0)