From 160f0cd4f3cb5171fbfdda97a7ffcd1f4a5df5b0 Mon Sep 17 00:00:00 2001 From: Fabrizio Duroni Date: Tue, 28 Apr 2026 00:13:32 +0200 Subject: [PATCH 1/2] refactor(test): re-enable test for retain batch region weh item append (react 19 differen) Co-authored-by: Copilot --- .../Lists/__tests__/VirtualizedList-test.js | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js b/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js index b02757cadf9..2c79bc843a0 100644 --- a/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js +++ b/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js @@ -1836,8 +1836,7 @@ it('retains initial render region when an item is appended', async () => { expect(component).toMatchSnapshot(); }); -// TODO: Revisit this test case after upgrading to React 19. -skipTestSilenceLinter( +it( 'retains batch render region when an item is appended', async () => { const items = generateItems(10); @@ -1860,12 +1859,9 @@ skipTestSilenceLinter( viewport: {width: 10, height: 50}, content: {width: 10, height: 100}, }); - performAllBatches(); }); - await act(async () => { - await jest.runAllTimersAsync(); - }); + await advanceUntilLastCellIndexRendered(component, items.length - 1); await act(() => { component.update( @@ -2639,13 +2635,30 @@ async function advanceUntilRenderAreaChanged(component) { } await act(() => { - jest.advanceTimersToNextTimer(1); + performNextBatch(); }); } throw new Error(`Render area did not change`); } +async function advanceUntilLastCellIndexRendered(component, targetLastIndex) { + const instance = component.getInstance(); + const MAX_TIMER_STEPS = 20; + + for (let step = 0; step < MAX_TIMER_STEPS; step++) { + if (instance.state.cellsAroundViewport.last === targetLastIndex) { + return; + } + + await act(() => { + performNextBatch(); + }); + } + + throw new Error(`Target last index ${targetLastIndex} not rendered`); +} + function performAllBatches() { jest.runAllTimers(); } From a7a6905fce46531b4ac3dd1c1e471a4bc5a6a600 Mon Sep 17 00:00:00 2001 From: Fabrizio Duroni Date: Wed, 29 Apr 2026 21:32:45 +0200 Subject: [PATCH 2/2] chore: linting --- .../Lists/__tests__/VirtualizedList-test.js | 77 +++++++++---------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js b/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js index 2c79bc843a0..6fe771ea183 100644 --- a/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js +++ b/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js @@ -1836,52 +1836,49 @@ it('retains initial render region when an item is appended', async () => { expect(component).toMatchSnapshot(); }); -it( - 'retains batch render region when an item is appended', - async () => { - const items = generateItems(10); - const ITEM_HEIGHT = 10; +it('retains batch render region when an item is appended', async () => { + const items = generateItems(10); + const ITEM_HEIGHT = 10; - let component; - await act(() => { - component = create( - , - ); - }); + let component; + await act(() => { + component = create( + , + ); + }); - await act(() => { - simulateLayout(component, { - viewport: {width: 10, height: 50}, - content: {width: 10, height: 100}, - }); + await act(() => { + simulateLayout(component, { + viewport: {width: 10, height: 50}, + content: {width: 10, height: 100}, }); + }); - await advanceUntilLastCellIndexRendered(component, items.length - 1); + await advanceUntilLastCellIndexRendered(component, items.length - 1); - await act(() => { - component.update( - , - ); - }); + await act(() => { + component.update( + , + ); + }); - // Adding an item to the list after batch render should keep the existing - // rendered items rendered. We batch render 10 items, then add an 11th. Expect - // the first ten items to be present, with a spacer for the 11th until the - // next batch render. - expect(component).toMatchSnapshot(); - }, -); + // Adding an item to the list after batch render should keep the existing + // rendered items rendered. We batch render 10 items, then add an 11th. Expect + // the first ten items to be present, with a spacer for the 11th until the + // next batch render. + expect(component).toMatchSnapshot(); +}); it('constrains batch render region when an item is removed', async () => { const items = generateItems(10);