From 8036fd94daea937247a8266ee6f0299e78cbe265 Mon Sep 17 00:00:00 2001 From: Minh Vu Date: Sun, 9 Aug 2026 21:33:01 +0200 Subject: [PATCH] fix(virtualized-lists): invalidate content length on orientation change --- .../Lists/ListMetricsAggregator.js | 1 + .../__tests__/ListMetricsAggregator-test.js | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/packages/virtualized-lists/Lists/ListMetricsAggregator.js b/packages/virtualized-lists/Lists/ListMetricsAggregator.js index 56d57e20fc00..b0516e6f7af1 100644 --- a/packages/virtualized-lists/Lists/ListMetricsAggregator.js +++ b/packages/virtualized-lists/Lists/ListMetricsAggregator.js @@ -319,6 +319,7 @@ export default class ListMetricsAggregator { if (orientation.horizontal !== this._orientation.horizontal) { this._cellMetrics.clear(); this._averageCellLength = 0; + this._contentLength = null; this._highestMeasuredCellIndex = 0; this._measuredCellsLength = 0; this._measuredCellsCount = 0; diff --git a/packages/virtualized-lists/Lists/__tests__/ListMetricsAggregator-test.js b/packages/virtualized-lists/Lists/__tests__/ListMetricsAggregator-test.js index 7b5e416d4196..36b50e88e867 100644 --- a/packages/virtualized-lists/Lists/__tests__/ListMetricsAggregator-test.js +++ b/packages/virtualized-lists/Lists/__tests__/ListMetricsAggregator-test.js @@ -986,6 +986,43 @@ describe('ListMetricsAggregator', () => { expect(listMetrics.getContentLength()).toBe(25); }); + it('invalidates content length when list orientation changes', () => { + const listMetrics = new ListMetricsAggregator(); + const verticalOrientation = {horizontal: false, rtl: false}; + const horizontalOrientation = {horizontal: true, rtl: false}; + const horizontalRtlOrientation = {horizontal: true, rtl: true}; + const cellLayout = {height: 50, width: 100, x: 0, y: 0}; + + listMetrics.notifyListContentLayout({ + layout: {height: 800, width: 400}, + orientation: verticalOrientation, + }); + expect(listMetrics.hasContentLength()).toBe(true); + + listMetrics.notifyCellLayout({ + cellIndex: 0, + cellKey: '0', + orientation: horizontalOrientation, + layout: cellLayout, + }); + expect(listMetrics.hasContentLength()).toBe(false); + + expect(() => + listMetrics.notifyCellLayout({ + cellIndex: 0, + cellKey: '0', + orientation: horizontalRtlOrientation, + layout: cellLayout, + }), + ).toThrow(); + + listMetrics.notifyListContentLayout({ + layout: {height: 50, width: 500}, + orientation: horizontalRtlOrientation, + }); + expect(listMetrics.getContentLength()).toBe(500); + }); + it('requires contentLength to resolve RTL metrics', () => { const listMetrics = new ListMetricsAggregator(); const orientation = {horizontal: true, rtl: true};