From 7e4171a5c3f7520d916d5666a15539749c9c5acf Mon Sep 17 00:00:00 2001 From: Dongda Li Date: Fri, 7 Aug 2026 22:05:58 -0400 Subject: [PATCH] fix(ios): make unmount assert message bounds-safe --- .../Mounting/ComponentViews/View/RCTViewComponentView.mm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 223670890e9..39746243264 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];