[Android] Crash in removeViewAt ("Unable to find parentView for tag") when a view is flattened in the commit right after it mounts

Đang mở
#60,018 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@erennyuksell đang làm issue này rồi.

Từ ngày 16/11/2026.

  • #60019 của @erennyuksell — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
android, java, react-native
Lĩnh vực
backend, mobile

Hướng nghiên cứu

Read the linked fix in pull request #60019 and trace the reported mount sequence around maybePreallocateShadowNode, executeMount, and Android view preallocation. The issue includes a reproducer and logs; use them to check the race and whether the proposed fix prevents it. Done means the release build no longer crashes through the reported sequence.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Description

After moving to 0.88.1 our Android release build started crashing now and then with Unable to find parentView for tag 1878 from SurfaceMountingManager.removeViewAt. Right before the crash there are a few soft exceptions like Unable to find viewState for tag: [1878] for addViewAt. I think this is the same crash as #58526.

I turned on enableFabricLogs and followed the tag through the mount items. It's a race between view preallocation and executeMount:

  1. A View is created in a small update, so maybePreallocateShadowNode queues it.
  2. The first commit has the View with opacity, so it's a real view. executeMount sends CREATE and adds the tag to allocatedViewTags.
  3. A layout effect flattens it again in a second commit, same JS task. executeMount sends DELETE and erases the tag.
  4. Only now the UI thread drains the queue. The tag isn't in allocatedViewTags anymore, so it gets added back and preallocated in Java, and the DELETE that is already queued removes that Java view. On the C++ side the tag stays allocated, with nothing behind it.
  5. The next time the same view turns into a real view, its CREATE is skipped because the tag looks allocated. INSERT goes into a view that doesn't exist (the soft exceptions), and UPDATE EVENTEMITTER leaves the placeholder ViewState from #58526.
  6. When it's flattened again, REMOVE from that placeholder throws.

With disableViewPreallocationAndroid the crash is gone. In our app it was the copy button of a code row: the wrapper gets opacity when the code expires and loses it when the next code comes in.

I have a fix that skips preallocation for families that are already part of a committed tree: #60019

Steps to reproduce
  1. Clone the reproducer below.
  2. cd ReproducerApp/android && ./gradlew assembleRelease, install the APK.
  3. Open the app. It closes within a few seconds (5 out of 5 launches on an API 36 emulator, between 4 and 18 seconds).

The repro mounts a new wrapper every 1.5 s, flattens it in a layout effect, then gives it opacity again after 400 ms and takes it away after 800 ms.

React Native Version

0.88.1

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info
System:
  OS: macOS 26.6.2
  CPU: (14) arm64 Apple M3 Max
  Memory: 259.25 MB / 36.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.22.2
  Yarn:
    version: 1.22.22
  npm:
    version: 10.9.7
  Watchman:
    version: 2025.12.15.00
IDEs:
  Android Studio: 2025.1 AI-251.25410.109.2511.13752376
  Xcode:
    version: 26.5/17F42
Languages:
  Java:
    version: 17.0.20.1
npmPackages:
  "@react-native-community/cli":
    installed: 20.2.0
    wanted: 20.2.0
  react:
    installed: 19.3.0
    wanted: 19.3.0
  react-native:
    installed: 0.88.1
    wanted: 0.88.1
Android:
  hermesEnabled: true
  newArchEnabled: true
Stacktrace or Logs
dispatchPreMountItems: PreAllocateViewMountItem [1878] - component: RCTView surfaceId: 21 isLayoutable: true
Executing mountItem: CREATE [1878] - layoutable:1 - RCTView
Executing mountItem: INSERT [1876]->[1878] @0
Executing mountItem: INSERT [1878]->[634] @4
...
Executing mountItem: REMOVE [1876]->[1878] @0
Executing mountItem: REMOVE [1878]->[634] @4
Executing mountItem: DELETE [1878]
-- 52 s later, no CREATE for 1878 --
Executing mountItem: INSERT [1878]->[634] @4
Executing mountItem: INSERT [1876]->[1878] @0
Executing mountItem: UPDATE EVENTEMITTER [1878]
ReactNoCrashSoftException: Unable to find viewState for tag: [1878] for addViewAt
Executing mountItem: REMOVE [1876]->[1878] @0
java.lang.IllegalStateException: Unable to find parentView for tag 1878
    at com.facebook.react.fabric.mounting.SurfaceMountingManager.removeViewAt(SurfaceMountingManager.kt)
    at com.facebook.react.fabric.mounting.mountitems.IntBufferBatchMountItem.execute(IntBufferBatchMountItem.kt)
    at com.facebook.react.fabric.mounting.MountItemDispatcher.executeOrEnqueue(MountItemDispatcher.kt)
    at com.facebook.react.fabric.mounting.MountItemDispatcher.dispatchMountItems(MountItemDispatcher.kt)
    at com.facebook.react.fabric.mounting.MountItemDispatcher.tryDispatchMountItems(MountItemDispatcher.kt)
    at com.facebook.react.fabric.FabricUIManager$DispatchUIFrameCallback.doFrameGuarded(FabricUIManager.java)
MANDATORY Reproducer

https://github.com/erennyuksell/rn-preallocation-crash

Ngôn ngữ chính
C++
Star
127k
Fork
25.5k
Merge trung bình
3 ngày 22 giờ
Pull request đã merge (30 ngày)
235

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của react/react-native

Tất cả issue của react/react-native

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.