diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm index 223670890e95..397462432644 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm @@ -255,15 +255,16 @@ - (void)unmountChildComponentView:(UIView *)childCompo childComponentView, @(index), @([childComponentView.superview tag])); + NSArray *containerSubviews = self.currentContainerView.subviews; + BOOL isIndexInBounds = index >= 0 && (NSUInteger)index < containerSubviews.count; RCTAssert( - (self.currentContainerView.subviews.count > index) && - [self.currentContainerView.subviews objectAtIndex:index] == childComponentView, + isIndexInBounds && [containerSubviews objectAtIndex:index] == childComponentView, @"Attempt to unmount a view which has a different index. (parent: %@, child: %@, index: %@, actual index: %@, tag at index: %@)", self, childComponentView, @(index), - @([self.currentContainerView.subviews indexOfObject:childComponentView]), - @([[self.currentContainerView.subviews objectAtIndex:index] tag])); + @([containerSubviews indexOfObject:childComponentView]), + isIndexInBounds ? @([[containerSubviews objectAtIndex:index] tag]) : @"out of bounds"); } [childComponentView removeFromSuperview];