Repository navigation
Conversation
| } | ||
|
|
||
| let sizes = nodes.map(node => | ||
| isElementVisible(node) ? new Size(node.scrollWidth, node.scrollHeight) : null |
There was a problem hiding this comment.
Perhaps we could also just check visibility once for the collection, now that the initial measuring is hoisted.
There was a problem hiding this comment.
I think this would mean we are checking every element on every render rather than only the ones with estimated sizes
There was a problem hiding this comment.
I'm not sure I can follow? I meant checking visibility of the scrollRef instead of once per item. The visibility check was introduced to prevent items from performing their initial measurement while the collection is hidden.
| state: VirtualizerState<T, V>, | ||
| _ref: RefObject<HTMLElement | null> | ||
| ): VirtualizerAria { | ||
| useLayoutEffect(() => { |
There was a problem hiding this comment.
Doesn't this mean that the size will only update if the entire virtualizer re-renders, not if only a single child does? React won't fire effects for parents when children update.
There was a problem hiding this comment.
Yes it does, but isn't that fine in this case? This is only for the initial measurement of an item, which can only happen if virtualizer re-renders. Other child size changes can be disregarded if the flag for the RO is off, no?
Also, in RAC, did VirtualizerItem even run its effect on child re-render before this change? If I'm not mistaken, the wrapper and its rendered node don't share a component boundary?
There was a problem hiding this comment.
Can we try keeping the size measurement in the item, but batching the react re-render? Basically inside updateItemSize schedule a requestAnimationFrame (if we haven't already) and run the invalidate inside it. That would keep measuring synchronous but result in only one react re-render instead of one per item.
There was a problem hiding this comment.
React is already batching the invalidation re-render anyway, so I’m not sure I understand the idea behind that? The issue is that we force at least one (currently 2) style recalculation for every item. That can't be avoided as long as useVirtualizerItem does the measuring I think?
There was a problem hiding this comment.
I thought the issue was that for each item we measure, update, measure, update etc, and this changes it to measure, measure, update.
There was a problem hiding this comment.
Ah, no. It's that we temporarily unset the height, then measure scrollHeight to get the content size. That forces the first style recalc. Then we call checkVisibility after resetting the height, which forces a second one. We can get this down to one, but we can't avoid both. This PR essentially tries to batch these operations, so that the browser only needs to recalc styles once.
Closes #10858
Each item with an estimated size forced two style and layout passes, one for
isElementVisibleafter the previous item restored itsstyle.heightand one for its owngetSizeafter clearing it, souseVirtualizernow clears all heights, reads all sizes and restores them in a single pass per commit.