Skip to content

VirtualizedList / FlatList loops onContentSizeChange indefinitely after width change when scrolled deep #60251

Backlog

Description

@BasixKOR

Description

After a vertical VirtualizedList / FlatList (@react-native/virtualized-lists) changes width (cross-axis length) while scrolled deep—such as unfolding/folding a foldable device, rotating, or resizing in split screen—onContentSizeChange fires roughly every 80–100 ms indefinitely with no touch input. Content heights cycle between 2–3 values (for example 38731.4 <-> 40076.2) or creep continuously, the render window keeps moving, and visible rows jump. In one instrumented run, the window walked from row 36 to row 1966 (of 2000) in ~40 s with no input, while the interior spacer stayed ~12k dp and content height stayed ~33k dp.

This requires a vertical list with variable-height rows whose height depends on width, no getItemLayout, a tall ListHeaderComponent (600 dp in the repro), and fast flings so the render window skips rows that never mount (and are never measured).

The cause is two-part: ListMetricsAggregator retains unmounted cells' old-width offsets and lengths across a cross-axis length change and still treats them as exact, while getCellMetricsApprox estimates unmeasured cells below the highest measured index as averageCellLength * index, ignoring ListHeaderComponent length and nearby measured cells. Mixing stale, fresh, and estimated offsets breaks the monotonicity assumed by elementsThatOverlapOffsets and causes the interior spacer and render window to oscillate.

First seen in a production app on a Galaxy Fold on React Native 0.86.2 (@react-native/virtualized-lists@0.86.2), and reproduced on 0.88.1 (latest stable) and on 0.90.0-nightly-20261124-ad969b283 (main @ ad969b28378), where ListMetricsAggregator.js and VirtualizedList.js are byte-identical to main.

Steps to reproduce

  1. Clone https://github.com/BasixKOR/virtualized-list-repro (the community reproducer template; the list is in ReproducerApp/App.tsx), then cd ReproducerApp && yarn install && yarn start.
  2. yarn android on an Android emulator (tested on Medium Phone AVD 1080x2400 420dpi API 37; New Architecture on, Hermes on).
  3. Start narrow: adb shell wm size 1080x2400 (or 1000x2208 for folded Fold dimensions).
  4. Perform 5–8 fast flings up to scroll deep (~30k dp) so the render window skips rows.
  5. Switch to wide: adb shell wm size 1768x2400 (unfold), then perform ~6 more flings.
  6. Switch back to narrow: adb shell wm size 1080x2400 (fold).
  7. Perform one fling, let go, and do not touch the screen.
  8. Watch logcat: adb logcat -s ReactNativeJS | grep VLREPRO.

Expected: onContentSizeChange stops within 1–2 s.
Actual: onContentSizeChange keeps firing every ~80–100 ms and visible rows keep changing.

scripts/repro.sh in the repo runs steps 3–8. It needs the app installed, Metro running, the app not already open, and one device attached (or ANDROID_SERIAL set). Events in the 30 s after the last fling: 422, 325, 334 on 0.88.1 and 380, 383, 328 on the nightly; with the wm size 1768x2400 step removed, 0, 0 on both:

adb shell wm size 1080x2400; adb shell am start -n com.reproducerapp/.MainActivity; sleep 8
for i in $(seq 8); do adb shell input swipe 540 1800 540 600 80; sleep 0.12; done   # deep, fast
adb shell wm size 1768x2400; sleep 3                                                # "unfold"
for i in $(seq 6); do adb shell input swipe 884 1800 884 600 80; sleep 0.25; done
adb shell wm size 1080x2400; sleep 3                                                # "fold"
adb shell input swipe 540 1800 540 600 80                                           # one fling, then hands off
adb logcat -s ReactNativeJS | grep contentSize

React Native Version

0.88.1 (also 0.90.0-nightly-20261124-ad969b283 = main @ ad969b28378; first seen on 0.86.2)

Affected Platforms

Runtime - Android

(iOS was not tested; the affected code in @react-native/virtualized-lists is platform-independent JS.)

Output of npx @react-native-community/cli info

System:
  OS: macOS 27.2.1
  CPU: (14) arm64 Apple M4 Pro
  Memory: 276.48 MB / 24.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 26.13.0
    path: ~/.local/share/mise/installs/node/latest/bin/node
  Yarn: Not Found
  npm:
    version: 11.20.0
    path: ~/.local/share/mise/installs/node/latest/bin/npm
  Watchman:
    version: 2026.10.26.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.17.0
    path: ~/.local/share/mise/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 27.2
      - iOS 27.2
      - macOS 27.2
      - tvOS 27.2
      - visionOS 27.2
      - watchOS 27.2
  Android SDK:
    API Levels:
      - "33"
      - "34"
      - "36"
      - "36"
      - "37"
    Build Tools:
      - 34.0.0
      - 35.0.0
      - 36.0.0
      - 36.1.0
      - 37.0.0
    System Images:
      - android-37.0 | 16 KB Page Size Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2026.2 AI-262.10968.63.2622.16975389
  Xcode:
    version: 27.2/27B52
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 25.0.5.0.2
    path: ~/.local/share/mise/shims/javac
  Ruby:
    version: 4.0.10
    path: ~/.local/share/mise/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 22.0.0-alpha.0
    wanted: 22.0.0-alpha.0
  react:
    installed: 19.3.0
    wanted: 19.3.0
  react-native:
    installed: 0.90.0-nightly-20261124-ad969b283
    wanted: nightly
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Stacktrace or Logs

Measurements (`onContentSizeChange` count in 30 s after last fling, no touch):

| build | width change | runs | events |
| --- | --- | --- | --- |
| main, 1080<->1768 x 2400 | yes | 3 | 406, 348, 353 |
| main, 1000<->1768 x 2208 (Fold sizes) | yes | 2 | 347, 385 |
| main, control: same flings, no width change | no | 2 | 0, 0 |
| main, slow deep scroll (1.5 s between flings, every row mounted) | yes | 2 | 0, 0 |
| + suggested fix (both parts) | yes | 3 | 0, 0, 0 |
| + fix part 1 only | yes | 2 | 320, 329 |
| + fix part 2 only | yes | 2 | 345, 344 |
| + PR #58916 | yes | 2 | 363, 362 |
| 0.88.1 (ReproducerApp), `scripts/repro.sh` | yes | 3 | 422, 325, 334 |
| 0.88.1 (ReproducerApp), same script, no width change | no | 2 | 0, 0 |

Height samples at rest:


main, Fold sizes      h=38731.4 h=38731.8 h=40076.2 h=38731.4 h=38732.6 h=38732.2 h=40077.0 h=38732.2 ...
part 1 only           h=40536.4 h=41873.9 h=40536.4 h=41873.9 h=40536.4 h=41873.9 ...
main, phone sizes     h=34043.8 h=32820.6 h=31597.3 h=30374.1 h=29150.9 h=31597.3 h=35267.0 h=37713.5 ...


Probe logs (`console.log` added in the spacer branch of `VirtualizedList.render`, with the list back at 381 dp after being 674 dp):


VLPROBE spacer [10,1455] size=12284 first={i:10,off:4944,len:382,mounted:false}(stored) last={i:1455,off:17037,len:191,mounted:true}(stored) avg=295.9 width=381
VLPROBE spacer [10,1459] size=12130 first={i:10,off:4944,len:382,mounted:false}(stored) last={i:1459,off:16834,len:240,mounted:true}(stored) avg=295.8 width=381
VLPROBE spacer [10,1463] size=11976 first={i:10,off:4944,len:382,mounted:false}(stored) last={i:1463,off:16730,len:191,mounted:true}(stored) avg=295.8 width=381


Probe time series of interior spacer `[first,last]`:


15:32:24 [10,36]   15:32:31 [10,389]   15:32:38 [10,732]   15:32:45 [10,1143]
15:32:52 [10,1486] 15:32:59 [10,1829]  15:33:03 [10,1816]  ... 15:33:39 [10,1647]

MANDATORY Reproducer

https://github.com/BasixKOR/virtualized-list-repro

Screenshots and Videos

Android emulator, stock nightly, after the width change: the list keeps advancing through rows on its own, from about 758 to 1116 in 8.5 s, with no touch input. This recording is from the run where the window walked down the list; other runs cycle between 2–3 heights instead.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions