File tree Expand file tree Collapse file tree
packages/virtualized-lists/Lists Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -103,9 +103,16 @@ export default class ListMetricsAggregator {
103103 this . _measuredCellsCount += 1 ;
104104 }
105105
106+ // NOTE: _measuredCellsCount is incremented before this line whenever a new
107+ // cell is added, so it should never be 0 here. This guard is defense in
108+ // depth against a future bug where _measuredCellsCount is reset (e.g. during
109+ // orientation changes) without also clearing _cellMetrics — which would leave
110+ // `curr` with a stale value and count === 0, causing a divide-by-zero.
106111 if ( this . _measuredCellsCount > 0 ) {
107112 this . _averageCellLength =
108113 this . _measuredCellsLength / this . _measuredCellsCount ;
114+ } else {
115+ this . _averageCellLength = 0 ;
109116 }
110117 this . _cellMetrics . set ( cellKey , next ) ;
111118 this . _highestMeasuredCellIndex = Math . max (
You can’t perform that action at this time.
0 commit comments