[Android] Crash in removeViewAt ("Unable to find parentView for tag") when a view is flattened in the commit right after it mounts
维护者通常 2 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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:
- A View is created in a small update, so
maybePreallocateShadowNodequeues it. - The first commit has the View with
opacity, so it's a real view.executeMountsendsCREATEand adds the tag toallocatedViewTags. - A layout effect flattens it again in a second commit, same JS task.
executeMountsendsDELETEand erases the tag. - Only now the UI thread drains the queue. The tag isn't in
allocatedViewTagsanymore, so it gets added back and preallocated in Java, and theDELETEthat is already queued removes that Java view. On the C++ side the tag stays allocated, with nothing behind it. - The next time the same view turns into a real view, its
CREATEis skipped because the tag looks allocated.INSERTgoes into a view that doesn't exist (the soft exceptions), andUPDATE EVENTEMITTERleaves the placeholderViewStatefrom #58526. - When it's flattened again,
REMOVEfrom 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
- Clone the reproducer below.
cd ReproducerApp/android && ./gradlew assembleRelease, install the APK.- 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
- 主要语言
- C++
- 星标
- 127k
- 派生
- 25.5k
- 平均合并
- 3 天 22 小时
- 30 天内合并 PR
- 235
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
react/react-native 的其他 Issue
-
Needs: Author Feedback Needs: Repro
难度 2/5 1-3 小时 新手友好度 82/100
react/react-native#60059 · 1 条评论 ·
维护者通常 2 天内回复
-
Needs: Triage :mag:
难度 2/5 1-3 小时 新手友好度 70/100
react/react-native#60000 ·
维护者通常 2 天内回复
-
`yarn test-ios` exits before building RNTester: `objc-test.sh` launches the WebSocket server script #59433 deleted可能已有人在做 @lazerg 于 4 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
react/react-native#59939 ·
维护者通常 2 天内回复
-
iOS Fabric pointer-handler reset leaves the next lone touch non-primary可能已有人在做 @alleneubank 于 6 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
react/react-native#59919 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
react/react-native#59722 ·
维护者通常 2 天内回复
查看 react/react-native 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
petercorke/robotics-toolbox-python#943 · 1 条评论 ·
维护者通常 1 天内回复
-
area:build bug
难度 1/5 1 小时以内 新手友好度 90/100
NatronGitHub/openfx-arena#71 ·
维护者通常 1 天内回复
-
upstream-blocked
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
ROCm/FastFlowLM#1057 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
NatronGitHub/openfx-gmic#45 ·
维护者通常 1 天内回复