Skip to content

[iOS][Fabric] Recycled RCTViewComponentView keeps its custom container, children end up out of order ("Attempt to unmount a view which has a different index") #60140

Open

Description

@marvin-splitt

Description

This is the mechanism suspected in #59166 (closed as stale for lack of runtime evidence), now confirmed at runtime with lldb on RN 0.88.1. Because the prebuilt Release artifacts keep RCTAssert compiled in (#57454), it can crash production apps, not just debug builds.

RCTViewComponentView uses a custom container view when styleWouldClipOverflowInk is true (overflow: hidden plus boxShadow or an outline). prepareForRecycle does not reset _useCustomContainerView, so a recycled view starts its next life with the flag still YES:

  1. updateProps reads currentContainerView, which creates a new _containerView.
  2. The new children mount into that container.
  3. finalizeUpdates sets the flag to NO, then invalidateLayer adds _backgroundColorLayer / _borderLayer with addSublayer:.
  4. The next currentContainerView call tears the container down with addSubview:, which appends the children after those layers.

From then on insertSubview:atIndex: (which indexes sublayers) puts each new child one slot early, and the native order diverges from the shadow tree. The next index-based unmount fails Attempt to unmount a view which has a different index. With asserts stripped, the child just sits one step lower in the stacking order and VoiceOver reads the siblings out of order.

Runtime evidence (lldb, iOS 27.0 simulator, RN 0.88.1 prebuilt core)

Breakpoints on mountChildComponentView:index: / unmountChildComponentView:index: for one freshly mounted row view (props: backgroundColor, borderTopWidth: 0 with a borderTopColor; no overflow, shadow or outline):

MOUNT   child=6722 idx=0  subviews_before=[0]          currentContainerView != self   <- stale container
MOUNT   child=6726 idx=1  subviews_before=[0]          currentContainerView != self
addSubview: 6722 (container teardown)  subviews_before=[0]
addSubview: 6726 (container teardown)  subviews_before=[0,6722]
UNMOUNT child=6726 idx=1  subviews_before=[6722,6726]
MOUNT   child=6868 idx=1  subviews_before=[6722]       currentContainerView == self

Expected order [6722, 6868]. The row's layer.sublayers afterwards:

[ CALayer zPosition -1024 (background), 6868, CALayer zPosition -1023 (border), 6722 ]

so subviews is [6868, 6722]. The next commit that removes 6868 at index 1 asserts.

In the app, the views that leave the stale flag behind are cards with overflow: 'hidden' + boxShadow in a swipeable carousel, where each swipe unmounts some cards. A typical repro: about 5 swipe/tap rounds trips the assert in a debug build. Moving the shadow to an outer view and the clip to an inner view makes it go away; after that change, no view in the app holds a custom container.

strings React.xcframework/ios-arm64/React.framework/React on react-native-artifacts-0.88.1-reactnative-core-release.tar.gz still contains Attempt to unmount a view which has a different index, so #57454 applies to 0.88.1.

Steps to reproduce

  1. Render a View with overflow: 'hidden' and a boxShadow, then unmount it, so its native view goes to the recycle pool.
  2. Mount a new View with a backgroundColor (separate background layer) or a non-uniform border, holding two or more children, so it may dequeue that recycled view.
  3. In a later commit, replace a non-first child (for example by changing its key).
  4. In a later commit again, remove that child.

I haven't built a standalone reproducer; the evidence above comes from an app. Happy to run a candidate repro or add more lldb output.

Suggested fix

  • Reset _useCustomContainerView = NO (and drop any _containerView) in prepareForRecycle.
  • When tearing the container down, insert its subviews at the container's position (for example insertSubview:belowSubview:_containerView) instead of appending them after other sublayers.

Workaround

Never combine overflow: hidden with boxShadow or an outline on one view: shadow on an outer view, clip on an inner one.

React Native Version

0.88.1

Affected Platforms

Runtime - iOS

Areas

Fabric - The New Renderer

Output of npx react-native info

react-native: 0.88.1 (prebuilt React Native core), Expo SDK 58, New Architecture, Hermes
iOS 27.0 simulator, Xcode 27.1

Stacktrace or Logs

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempt to unmount a view which has a different index. (parent: <RCTViewComponentView ...>, child: <RCTParagraphComponentView ...>, ...)'
  React  _RCTAssertFormat
  React  -[RCTViewComponentView unmountChildComponentView:index:]
  React  RCTPerformMountInstructions(...)
  React  -[RCTMountingManager performTransaction:]
  React  facebook::react::TelemetryController::pullTransaction(...)
  React  -[RCTMountingManager initiateTransaction:]

Reproducer

No standalone reproducer yet (see Steps to reproduce).

Activity

  1. react-native-bot commented on Nov 19, 2026

    @react-native-bot
    Collaborator

    Warning

    Missing reproducer: We could not detect a reproducible example in your issue report. Reproducers are mandatory and we can accept only one of those as a valid reproducer:


    You can read more about about it on our website: How to report a bug.

  2. added a commit that references this issue on Nov 19, 2026
  3. marvin-splitt commented on Nov 19, 2026

    @marvin-splitt
    Author

    Reproducer: #60141 edits RNTesterPlayground.js.

    Four taps on one screen, deterministic on RN 0.88.1 (iOS 27.0 simulator, debug):

    1. Unmounts a View with overflow: 'hidden' + boxShadow, so its native view goes to the recycle pool.
    2. Mounts a bordered View (collapsable={false}, borderTopWidth) with two absolutely positioned children. It dequeues the recycled view and mounts the children through the stale container.
    3. Replaces the second child (new key). It lands behind the first one: the green square is hidden under the red box.
    4. Replaces it again. Removing the previous one asserts Attempt to unmount a view which has a different index.

    Crashed in 2 of 2 runs. With the boxShadow removed from the first view (control), all four steps render correctly and nothing asserts.

    On main and v0.89.0-rc.2, prepareForRecycle still doesn't reset _useCustomContainerView. debaf42 (#59628) reconciles the container before the ownership check in unmountChildComponentView:index:, but doesn't change where the children end up, so the index assertion and the wrong stacking order should remain. I haven't run the reproducer on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: AttentionIssues where the author has responded to feedback.Needs: ReproThis issue could be improved with a clear list of steps to reproduce the issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions