From eff7aa29e9ea21827c9b16fedb0cb89962030ea1 Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Thu, 15 Oct 2026 11:12:09 -0700 Subject: [PATCH] fix(macos): keep the view's shadow color alive On macOS, RCTView declares shadowColor as an assign CGColorRef property, so it kept the color it was given without retaining it. That color is autoreleased, so by the time didUpdateShadow read it, it could already be freed, which crashed. Convert the color to an NSColor as soon as it's set, and keep that instead. Setting it to NULL clears the color. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 33ac4470-c1d2-43c0-92ee-8407909f0f6a --- packages/react-native/React/Views/RCTView.m | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/react-native/React/Views/RCTView.m b/packages/react-native/React/Views/RCTView.m index e21035af2c47..cb856fc0b628 100644 --- a/packages/react-native/React/Views/RCTView.m +++ b/packages/react-native/React/Views/RCTView.m @@ -143,6 +143,7 @@ @implementation RCTView { NSTrackingArea *_trackingArea; BOOL _hasMouseOver; BOOL _mouseDownCanMoveWindow; + NSColor *_innerShadowColor; #endif // macOS] NSMutableDictionary *accessibilityActionsNameMap; NSMutableDictionary *accessibilityActionsLabelMap; @@ -731,11 +732,8 @@ - (NSString *)description #if TARGET_OS_OSX // [macOS - (void)setShadowColor:(CGColorRef)shadowColor { - if (_shadowColor != shadowColor) - { - _shadowColor = shadowColor; - [self didUpdateShadow]; - } + _innerShadowColor = shadowColor != NULL ? [NSColor colorWithCGColor:shadowColor] : nil; + [self didUpdateShadow]; } - (void)setShadowOffset:(CGSize)shadowOffset @@ -768,11 +766,7 @@ - (void)setShadowRadius:(CGFloat)shadowRadius -(void)didUpdateShadow { NSShadow *shadow = [NSShadow new]; - NSColor *baseShadowColor = nil; - if (_shadowColor != NULL) { - baseShadowColor = [NSColor colorWithCGColor:_shadowColor]; - } - shadow.shadowColor = [baseShadowColor colorWithAlphaComponent:[self shadowOpacity]]; + shadow.shadowColor = [_innerShadowColor colorWithAlphaComponent:[self shadowOpacity]]; shadow.shadowOffset = [self shadowOffset]; shadow.shadowBlurRadius = [self shadowRadius]; [self setShadow:shadow];