Files
react-native/packages
zhongwuzw cbaff1c7aa Fabric: Fixes crash of dynamic color when light/dark mode changed (#48496)
Summary:
The reason is when light/dark mode changed, the `hash` value also changed because we used `color.getColor()`. leads to size balanced break.

```
Assertion failed: (index_.size() == lru_.size()), function size, file EvictingCacheMap.h, line 439.

(lldb) bt
* thread https://github.com/facebook/react-native/issues/1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00000001089a9108 libsystem_kernel.dylib`__pthread_kill + 8
    frame https://github.com/facebook/react-native/issues/1: 0x0000000105de3408 libsystem_pthread.dylib`pthread_kill + 256
    frame https://github.com/facebook/react-native/issues/2: 0x000000018016c4ec libsystem_c.dylib`abort + 104
    frame https://github.com/facebook/react-native/issues/3: 0x000000018016b934 libsystem_c.dylib`__assert_rtn + 268
  * frame https://github.com/facebook/react-native/issues/4: 0x00000001073e386c React_FabricComponents`folly::EvictingCacheMap<facebook::react::AttributedString, std::__1::shared_ptr<void>, folly::HeterogeneousAccessHash<facebook::react::AttributedString, void>, folly::HeterogeneousAccessEqualTo<facebook::react::AttributedString, void>>::size(this=0x0000600003900348) const at EvictingCacheMap.h:439:5
    frame https://github.com/facebook/react-native/issues/5: 0x00000001073e34f4 React_FabricComponents`void folly::EvictingCacheMap<facebook::react::AttributedString, std::__1::shared_ptr<void>, folly::HeterogeneousAccessHash<facebook::react::AttributedString, void>, folly::HeterogeneousAccessEqualTo<facebook::react::AttributedString, void>>::setImpl<facebook::react::AttributedString>(this=0x0000600003900348, key=0x000000016b9f20a8, value=nullptr, promote=true, pruneHook=folly::EvictingCacheMap<facebook::react::AttributedString, std::__1::shared_ptr<void>, folly::HeterogeneousAccessHash<facebook::react::AttributedString, void>, folly::HeterogeneousAccessEqualTo<facebook::react::AttributedString, void> >::PruneHookCall @ 0x000000016b9f1cc8) at EvictingCacheMap.h:674:27
    frame https://github.com/facebook/react-native/issues/6: 0x00000001073deb88 React_FabricComponents`folly::EvictingCacheMap<facebook::react::AttributedString, std::__1::shared_ptr<void>, folly::HeterogeneousAccessHash<facebook::react::AttributedString, void>, folly::HeterogeneousAccessEqualTo<facebook::react::AttributedString, void>>::set(this=0x0000600003900348, key=0x000000016b9f20a8, value=ptr = 0x60000024ae20 strong=2 weak=1, promote=true, pruneHook=folly::EvictingCacheMap<facebook::react::AttributedString, std::__1::shared_ptr<void>, folly::HeterogeneousAccessHash<facebook::react::AttributedString, void>, folly::HeterogeneousAccessEqualTo<facebook::react::AttributedString, void> >::PruneHookCall @ 0x000000016b9f1d98) at EvictingCacheMap.h:346:5
    frame https://github.com/facebook/react-native/issues/7: 0x00000001073d91dc React_FabricComponents`facebook::react::SimpleThreadSafeCache<facebook::react::AttributedString, std::__1::shared_ptr<void>, 256>::get(this=0x0000600003900348, key=0x000000016b9f20a8, generator= Lambda in File RCTTextLayoutManager.mm at Line 337) const at SimpleThreadSafeCache.h:40:12
    frame https://github.com/facebook/react-native/issues/8: 0x00000001073d9058 React_FabricComponents`-[RCTTextLayoutManager _nsAttributedStringFromAttributedString:](self=0x0000600003900340, _cmd="_nsAttributedStringFromAttributedString:", attributedString=AttributedString @ 0x000000016b9f20a8) at RCTTextLayoutManager.mm:337:42
    frame https://github.com/facebook/react-native/issues/9: 0x00000001073d6378 React_FabricComponents`-[RCTTextLayoutManager drawAttributedString:paragraphAttributes:frame:drawHighlightPath:](self=0x0000600003900340, _cmd="drawAttributedString:paragraphAttributes:frame:drawHighlightPath:", attributedString=AttributedString @ 0x000000016b9f23a8, paragraphAttributes=ParagraphAttributes @ 0x000000016b9f2378, frame=(origin = (x = 0, y = 0), size = (width = 92, height = 21.666748046875)), block=0x00000001061602d0) at RCTTextLayoutManager.mm:73:56
    frame https://github.com/facebook/react-native/issues/10: 0x000000010616020c RCTFabric`-[RCTParagraphTextView drawRect:](self=0x000000012beb9dc0, _cmd="drawRect:", rect=(origin = (x = 0, y = 0.000081380208335701809), size = (width = 92, height = 21.666666666666664))) at RCTParagraphComponentView.mm:346:3
    frame https://github.com/facebook/react-native/issues/11: 0x0000000186043e60 UIKitCore`-[UIView(CALayerDelegate) drawLayer:inContext:] + 584
    frame https://github.com/facebook/react-native/issues/12: 0x000000018af40080 QuartzCore`CABackingStoreUpdate_ + 244
    frame https://github.com/facebook/react-native/issues/13: 0x000000018b0bec88 QuartzCore`invocation function for block in CA::Layer::display_() + 108
    frame https://github.com/facebook/react-native/issues/14: 0x000000018b0b5524 QuartzCore`-[CALayer _display] + 1596
    frame https://github.com/facebook/react-native/issues/15: 0x000000018b0c7e74 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 392
    frame https://github.com/facebook/react-native/issues/16: 0x000000018affca50 QuartzCore`CA::Context::commit_transaction(CA::Transaction*, double, double*) + 464
    frame https://github.com/facebook/react-native/issues/17: 0x000000018b02b260 QuartzCore`CA::Transaction::commit() + 652
    frame https://github.com/facebook/react-native/issues/18: 0x000000018b02c7b4 QuartzCore`CA::Transaction::flush_as_runloop_observer(bool) + 68
    frame https://github.com/facebook/react-native/issues/19: 0x0000000185ad6c1c UIKitCore`_UIApplicationFlushCATransaction + 48
    frame https://github.com/facebook/react-native/issues/20: 0x0000000185a07ccc UIKitCore`__setupUpdateSequence_block_invoke_2 + 352
    frame https://github.com/facebook/react-native/issues/21: 0x000000018505d28c UIKitCore`_UIUpdateSequenceRun + 76
    frame https://github.com/facebook/react-native/issues/22: 0x0000000185a07670 UIKitCore`schedulerStepScheduledMainSection + 168
    frame https://github.com/facebook/react-native/issues/23: 0x0000000185a06aa8 UIKitCore`runloopSourceCallback + 80
    frame https://github.com/facebook/react-native/issues/24: 0x000000018041b7c4 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
    frame https://github.com/facebook/react-native/issues/25: 0x000000018041b70c CoreFoundation`__CFRunLoopDoSource0 + 172
    frame https://github.com/facebook/react-native/issues/26: 0x000000018041ae70 CoreFoundation`__CFRunLoopDoSources0 + 232
    frame https://github.com/facebook/react-native/issues/27: 0x00000001804153b4 CoreFoundation`__CFRunLoopRun + 788
    frame https://github.com/facebook/react-native/issues/28: 0x0000000180414c24 CoreFoundation`CFRunLoopRunSpecific + 552
    frame https://github.com/facebook/react-native/issues/29: 0x000000019020ab10 GraphicsServices`GSEventRunModal + 160
    frame https://github.com/facebook/react-native/issues/30: 0x0000000185ad82fc UIKitCore`-[UIApplication _run] + 796
    frame https://github.com/facebook/react-native/issues/31: 0x0000000185adc4f4 UIKitCore`UIApplicationMain + 124
    frame https://github.com/facebook/react-native/issues/32: 0x0000000104521f68 RNTester.debug.dylib`main(argc=1, argv=0x000000016b9f5af8) at main.m:15:12
    frame https://github.com/facebook/react-native/issues/33: 0x00000001045b9410 dyld_sim`start_sim + 20
    frame https://github.com/facebook/react-native/issues/34: 0x0000000104796274 dyld`start + 2840
```

## Changelog:

[IOS] [FIXED] - Fabric: Fixes crash of dynamic color when light/dark mode changed

Pull Request resolved: https://github.com/facebook/react-native/pull/48496

Test Plan:
RNTester -> PlatformColor example -> changed the dark/light mode  in the system settings -> go back to App and pop and push the PlatformColor example, it would crash:

![Simulator Screen Recording - iPhone 16 - 2025-01-05 at 15 46 08](https://github.com/user-attachments/assets/f6faaf80-ad03-49c6-9a56-b1117bdc2659)

Reviewed By: sammy-SC

Differential Revision: D68157559

Pulled By: cipolleschi

fbshipit-source-id: 01959845b742ce748186d3877b2792f0f9132ff5
2025-01-28 11:20:18 -08:00
..