fix(useVirtual): calculateVisibleItems: return if itemHeight is 0 #21442
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes an issue in
useVirtual
composable for dynamic item heights. If a staticitem-height
is not provided, the height is calculated for each item dynamically. However, depending on the timing when the table gets rendered initially, it may happen that thecalculateVisibleItems
function is being called before the item heights have been determined.If all heights are still 0,
binaryClosest
function calculates an index in the middle of the item array which leads to all items being rendered instead of lazy rendering.See the behavior in the playground here
Modifying items in
onMounted
causes the issue.The table only recovers if you clear the items or if you add more items and scroll past the initial virtual page.
The proposed solution adds an additional circuit breaker to the
_calculateVisibleItems
function in caseitemHeight
has not yet been calculated.This PR also fixes #18806
Markup: