From 817fedb0e7a5276d86431c65cc886062ed8fe220 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 31 Oct 2023 16:49:58 -0700 Subject: [PATCH] Bail on hiPri render on missing layout data before checking priority (#41270) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41270 `scheduleCellsToRenderUpdate()` is called in response to new measurements, or component changes. It has logic to decide whether to immediately calculate new state, or to defer it until a later batched period. It will not immediately update state if we don't yet have measurements for cells, but this condition is after another which calculates priority, relying on these measurements. These are garbage if we don't yet have measurements, and trigger an invariant violation in horizontal RTL. This switches around the conditions, to avoid offset resolution if we don't yet have valid measurements. I suspect some "hiPri" renders where cells shift are bugged right now when we update state in response to content size change, before we have new corresponding cell layouts. Changelog: [General][Fixed] - Bail on hiPri render on missing layout data before checking priority Reviewed By: yungsters Differential Revision: D50791506 fbshipit-source-id: 8dbffc37edd2a42f7842c0090d344dcd6f3e3c6d --- packages/virtualized-lists/Lists/VirtualizedList.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/virtualized-lists/Lists/VirtualizedList.js b/packages/virtualized-lists/Lists/VirtualizedList.js index 886e2ec657be0b..f257a0dc585990 100644 --- a/packages/virtualized-lists/Lists/VirtualizedList.js +++ b/packages/virtualized-lists/Lists/VirtualizedList.js @@ -1752,8 +1752,9 @@ class VirtualizedList extends StateSafePureComponent { // If this is triggered in an `componentDidUpdate` followed by a hiPri cellToRenderUpdate // We shouldn't do another hipri cellToRenderUpdate if ( + (this._listMetrics.getAverageCellLength() > 0 || + this.props.getItemLayout != null) && this._shouldRenderWithPriority() && - (this._listMetrics.getAverageCellLength() || this.props.getItemLayout) && !this._hiPriInProgress ) { this._hiPriInProgress = true;