From a60432f93f7d0be2c89fb68a6f0e9cb42c2ebad9 Mon Sep 17 00:00:00 2001 From: Jason Morse Date: Thu, 12 Nov 2026 22:25:09 +0000 Subject: [PATCH 1/4] test(fabric): cover native-props cloning and macOS resize Port the merge regression from MIT-licensed react/react-native commit 923e7ddcaf4d2de45ca7dedafbb84c6b87dbffc4 by OrfeasZ (#52646), preserving its license headers. Add native/React precedence and placeholder clone cases, a bounded concurrent clone case, and an in-process AppKit XCTest using the real Scheduler, SurfaceHandler and UIManager. The fixture never accesses the new mutex and can run unchanged against an unpatched baseline. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 33ea5c72-8bbd-448d-aa21-c9b99dd03c96 --- .../uimanager/tests/FabricUIManagerTest.cpp | 182 +++++++++++++++- .../RCTFabricNativePropsTests.mm | 197 ++++++++++++++++++ .../RNTesterPods.xcodeproj/project.pbxproj | 4 + 3 files changed, 380 insertions(+), 3 deletions(-) create mode 100644 packages/rn-tester/RNTester-macOSUnitTests/RCTFabricNativePropsTests.mm diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/tests/FabricUIManagerTest.cpp b/packages/react-native/ReactCommon/react/renderer/uimanager/tests/FabricUIManagerTest.cpp index c842a454b659..0d36f54cb85e 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/tests/FabricUIManagerTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/tests/FabricUIManagerTest.cpp @@ -5,13 +5,189 @@ * LICENSE file in the root directory of this source tree. */ +// [macOS Adapted from react/react-native@923e7ddcaf4d (#52646). +#include #include +#include #include +#include +#include +#include +#include #include -using namespace facebook::react; +namespace facebook::react { -TEST(UIManagerTest, testSomething) { - // TODO +class FabricUIManagerTest : public ::testing::Test { + public: + FabricUIManagerTest() { + contextContainer_ = std::make_shared(); + ComponentDescriptorProviderRegistry providers{}; + auto registry = providers.createComponentDescriptorRegistry( + {.eventDispatcher = EventDispatcher::Shared{}, + .contextContainer = contextContainer_, + .flavor = nullptr}); + providers.add( + concreteComponentDescriptorProvider()); + providers.add( + concreteComponentDescriptorProvider()); + builder_ = std::make_unique(registry); + + RuntimeExecutor executor = + [](std::function&& /*callback*/) {}; + uiManager_ = std::make_unique(executor, contextContainer_); + uiManager_->setComponentDescriptorRegistry(registry); + + std::shared_ptr root; + // clang-format off + builder_->build( + Element() + .tag(1) + .surfaceId(surfaceId_) + .reference(root) + .props([] { + auto props = std::make_shared(); + props->layoutConstraints = LayoutConstraints{ + .minimumSize = {.width = 0, .height = 0}, + .maximumSize = {.width = 500, .height = 500}}; + return props; + }) + .children({ + Element() + .tag(42) + .surfaceId(surfaceId_) + .props([] { + auto props = std::make_shared(); + props->nativeId = "initial"; + props->opacity = 1.0; + return props; + }) + })); + // clang-format on + + auto tree = std::make_unique( + surfaceId_, + LayoutConstraints{}, + LayoutContext{}, + *uiManager_, + *contextContainer_); + shadowTree_ = tree.get(); + tree->commit([&root](const RootShadowNode&) { return root; }, {true}); + uiManager_->startSurface( + std::move(tree), "test", folly::dynamic::object, DisplayMode::Visible); + } + + void TearDown() override { + uiManager_->stopSurface(surfaceId_); + } + + protected: + std::shared_ptr currentViewNode() const { + return shadowTree_->getCurrentRevision() + .rootShadowNode->getChildren() + .front(); + } + + const ViewProps& viewPropsInTree() const { + return static_cast(*currentViewNode()->getProps()); + } + + static const ViewProps& viewProps(const ShadowNode& node) { + return static_cast(*node.getProps()); + } + + SurfaceId surfaceId_{0}; + std::shared_ptr contextContainer_; + std::unique_ptr builder_; + std::unique_ptr uiManager_; + ShadowTree* shadowTree_{nullptr}; +}; + +TEST_F(FabricUIManagerTest, SetNativePropsMergesWithReactRender) { + ASSERT_EQ(viewPropsInTree().nativeId, "initial"); + ASSERT_FLOAT_EQ(viewPropsInTree().opacity, 1.0); + uiManager_->setNativeProps_DEPRECATED( + currentViewNode(), RawProps(folly::dynamic::object("opacity", 0.5))); + EXPECT_EQ(viewPropsInTree().nativeId, "initial"); + EXPECT_FLOAT_EQ(viewPropsInTree().opacity, 0.5); + + auto rendered = uiManager_->cloneNode( + *currentViewNode(), + nullptr, + RawProps(folly::dynamic::object("nativeID", "from-react"))); + EXPECT_EQ(viewProps(*rendered).nativeId, "from-react"); + EXPECT_FLOAT_EQ(viewProps(*rendered).opacity, 0.5); } + +TEST_F(FabricUIManagerTest, ReactRefreshesNativeOwnedKeysIncludingNull) { + uiManager_->setNativeProps_DEPRECATED( + currentViewNode(), RawProps(folly::dynamic::object("opacity", 0.5))); + auto refreshed = uiManager_->cloneNode( + *currentViewNode(), + nullptr, + RawProps(folly::dynamic::object("opacity", 0.75))); + EXPECT_FLOAT_EQ(viewProps(*refreshed).opacity, 0.75); + EXPECT_FLOAT_EQ(viewProps(*refreshed->clone({})).opacity, 0.75); + + auto reset = uiManager_->cloneNode( + *refreshed, + nullptr, + RawProps(folly::dynamic::object("opacity", nullptr))); + EXPECT_FLOAT_EQ(viewProps(*reset).opacity, 1.0); + EXPECT_FLOAT_EQ(viewProps(*reset->clone({})).opacity, 1.0); +} + +TEST_F(FabricUIManagerTest, ReactOnlyKeysDoNotBecomeNativeOverrides) { + uiManager_->setNativeProps_DEPRECATED( + currentViewNode(), RawProps(folly::dynamic::object("opacity", 0.5))); + auto rendered = uiManager_->cloneNode( + *currentViewNode(), + nullptr, + RawProps(folly::dynamic::object("nativeID", "from-react"))); + auto explicitProps = std::make_shared(); + explicitProps->nativeId = "explicit"; + explicitProps->opacity = 0.9; + auto explicitClone = rendered->clone({.props = explicitProps}); + EXPECT_EQ(viewProps(*explicitClone).nativeId, "explicit"); + EXPECT_FLOAT_EQ(viewProps(*explicitClone).opacity, 0.9); + + auto placeholderClone = explicitClone->clone({}); + EXPECT_EQ(viewProps(*placeholderClone).nativeId, "explicit"); + EXPECT_FLOAT_EQ(viewProps(*placeholderClone).opacity, 0.5); +} + +TEST_F( + FabricUIManagerTest, + ConcurrentReactAndPlaceholderClonesUseOwnedSnapshots) { + uiManager_->setNativeProps_DEPRECATED( + currentViewNode(), RawProps(folly::dynamic::object("opacity", 0.5))); + auto node = currentViewNode(); + std::atomic start{false}; + std::atomic invalidSnapshots{0}; + std::thread writer([&] { + while (!start.load()) { + std::this_thread::yield(); + } + for (int i = 0; i < 1000; ++i) { + uiManager_->cloneNode( + *node, + nullptr, + RawProps(folly::dynamic::object("opacity", i % 2 ? 0.75 : 0.25))); + } + }); + start.store(true); + for (int i = 0; i < 1000; ++i) { + auto clone = node->clone({}); + auto opacity = viewProps(*clone).opacity; + if (opacity != 0.25 && opacity != 0.5 && opacity != 0.75) { + ++invalidSnapshots; + } + } + writer.join(); + EXPECT_EQ(invalidSnapshots.load(), 0); + EXPECT_FLOAT_EQ(viewProps(*node->clone({})).opacity, 0.75); +} + +} // namespace facebook::react +// macOS] diff --git a/packages/rn-tester/RNTester-macOSUnitTests/RCTFabricNativePropsTests.mm b/packages/rn-tester/RNTester-macOSUnitTests/RCTFabricNativePropsTests.mm new file mode 100644 index 000000000000..e8c46373ec24 --- /dev/null +++ b/packages/rn-tester/RNTester-macOSUnitTests/RCTFabricNativePropsTests.mm @@ -0,0 +1,197 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] +#import +#import + +#if RCT_NEW_ARCH_ENABLED + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace facebook::react; + +@interface RCTNativePropsResizeDelegate : NSObject +@property (nonatomic, copy) void (^resize)(NSSize); +@end + +@implementation RCTNativePropsResizeDelegate +- (void)windowDidResize:(NSNotification *)notification +{ + NSWindow *window = notification.object; + self.resize(window.contentView.bounds.size); +} +@end + +@interface RCTFabricNativePropsTests : XCTestCase +@end + +@implementation RCTFabricNativePropsTests + +- (void)testWindowResizeWhileUpdatingNativeProps +{ + void (^run)(void) = ^{ + [NSApplication sharedApplication]; + auto context = std::make_shared(); + // The empty surface needs no JavaScript VM, input driver, or mounted views. + RuntimeExecutor executor = [](std::function &&) {}; + auto runtimeScheduler = std::make_shared(executor); + context->insert(RuntimeSchedulerKey, std::weak_ptr(runtimeScheduler)); + auto providers = std::make_shared(); + providers->add(concreteComponentDescriptorProvider()); + providers->add(concreteComponentDescriptorProvider()); + SchedulerToolbox toolbox{ + .contextContainer = context, + .componentRegistryFactory = + [providers]( + const EventDispatcher::Weak &dispatcher, const std::shared_ptr &container) { + return providers->createComponentDescriptorRegistry({dispatcher, container, nullptr}); + }, + .runtimeExecutor = executor, + .eventBeatFactory = + [runtimeScheduler](std::shared_ptr owner) { + return std::make_unique(std::move(owner), *runtimeScheduler); + }}; + Scheduler scheduler(toolbox, nullptr, nullptr); + SurfaceHandler surface("", 11); + scheduler.registerSurface(surface); + surface.constraintLayout( + {.minimumSize = {600, 400}, .maximumSize = {600, 400}, .layoutDirection = LayoutDirection::LeftToRight}, {}); + surface.start(); + auto uiManager = scheduler.getUIManager(); + auto node = uiManager->createNode( + 42, + "View", + 11, + RawProps(folly::dynamic::object("opacity", 0.5)("flex", 1)("nativeID", "resize-target")), + nullptr); + auto children = std::make_shared>>(); + children->push_back(node); + uiManager->completeSurface(11, children, {true}); + uiManager->setNativeProps_DEPRECATED(node, RawProps(folly::dynamic::object("opacity", 0.5))); + + constexpr size_t resizeCount = 120; + constexpr size_t updatesPerResize = 32; + std::mutex gate; + std::condition_variable changed; + size_t requested = 0; + size_t completed = 0; + bool stop = false; + std::atomic timedOut{false}; + std::atomic writes{0}; + std::atomic invalidSnapshots{0}; + auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(20); + + std::thread writer([&] { + for (size_t phase = 1; phase <= resizeCount; ++phase) { + { + std::unique_lock lock(gate); + if (!changed.wait_until(lock, deadline, [&] { return stop || requested >= phase; })) { + timedOut.store(true); + return; + } + if (stop) { + return; + } + } + for (size_t update = 0; update < updatesPerResize; ++update) { + uiManager->setNativeProps_DEPRECATED( + node, RawProps(folly::dynamic::object("opacity", update % 2 ? 0.75 : 0.25))); + ++writes; + } + { + std::lock_guard lock(gate); + completed = phase; + } + changed.notify_one(); + } + }); + + NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 600, 400) + styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskResizable + backing:NSBackingStoreBuffered + defer:NO]; + window.releasedWhenClosed = NO; + RCTNativePropsResizeDelegate *delegate = [RCTNativePropsResizeDelegate new]; + size_t callbacks = 0; + size_t clones = 0; + auto resize = [&](NSSize size) { + ++callbacks; + { + std::lock_guard lock(gate); + requested = callbacks; + } + changed.notify_one(); + surface.constraintLayout( + {.minimumSize = {size.width, size.height}, + .maximumSize = {size.width, size.height}, + .layoutDirection = LayoutDirection::LeftToRight}, + {}); + for (size_t i = 0; i < updatesPerResize; ++i) { + auto clone = node->clone({}); + auto opacity = static_cast(*clone->getProps()).opacity; + if (opacity != 0.25 && opacity != 0.5 && opacity != 0.75) { + ++invalidSnapshots; + } + ++clones; + } + }; + delegate.resize = ^(NSSize size) { + resize(size); + }; + window.delegate = delegate; + for (size_t i = 0; i < resizeCount; ++i) { + [window setContentSize:i % 2 ? NSMakeSize(1000, 740) : NSMakeSize(800, 600)]; + std::unique_lock lock(gate); + if (!changed.wait_until(lock, deadline, [&] { return completed >= i + 1; })) { + timedOut.store(true); + break; + } + } + { + std::lock_guard lock(gate); + stop = true; + } + changed.notify_one(); + writer.join(); + window.delegate = nil; + delegate.resize = nil; + [window close]; + + XCTAssertFalse(timedOut.load()); + XCTAssertEqual(callbacks, resizeCount); + XCTAssertEqual(completed, resizeCount); + XCTAssertEqual(writes.load(), resizeCount * updatesPerResize); + XCTAssertEqual(clones, resizeCount * updatesPerResize); + XCTAssertEqual(invalidSnapshots.load(), 0u); + XCTAssertEqual(surface.getLayoutConstraints().maximumSize.width, 1000); + auto finalClone = node->clone({}); + XCTAssertEqualWithAccuracy(static_cast(*finalClone->getProps()).opacity, 0.75, 0.0001); + surface.stop(); + scheduler.unregisterSurface(surface); + }; + if ([NSThread isMainThread]) { + run(); + } else { + dispatch_sync(dispatch_get_main_queue(), run); + } +} + +@end + +#endif diff --git a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj index 842c7c003929..474282a46fa1 100644 --- a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj +++ b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + FAB526460000000000000001 /* RCTFabricNativePropsTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAB526460000000000000002 /* RCTFabricNativePropsTests.mm */; }; /* [macOS] */ 08E25EBE4A584CD7B70FBB1E /* libPods-RNTester.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D74056A5352F0925816E50E0 /* libPods-RNTester.a */; }; 0CBC915D60C701A81731A5A4 /* libPods-RNTester-macOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C88AE81E635231C7F0F3BA4 /* libPods-RNTester-macOS.a */; }; 0E3E8DF4F87D07566A9489D4 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = AC276E71CF27E40DFA22979F /* PrivacyInfo.xcprivacy */; }; @@ -144,6 +145,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + FAB526460000000000000002 /* RCTFabricNativePropsTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTFabricNativePropsTests.mm; sourceTree = ""; }; /* [macOS] */ 07517909E4081E5D74D5DD60 /* libPods-RNTester-macOSUnitTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RNTester-macOSUnitTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 086F285685A842F5E52B6F9C /* Pods-RNTester-visionOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNTester-visionOS.debug.xcconfig"; path = "Target Support Files/Pods-RNTester-visionOS/Pods-RNTester-visionOS.debug.xcconfig"; sourceTree = ""; }; 0EA618022BE537D3001875EF /* RNTesterBundle.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; name = RNTesterBundle.bundle; path = RNTester/RNTesterBundle.bundle; sourceTree = ""; }; @@ -466,6 +468,7 @@ ACC52F56299ECB8A002A2B0B /* RNTester-macOSUnitTests */ = { isa = PBXGroup; children = ( + FAB526460000000000000002 /* RCTFabricNativePropsTests.mm */, /* [macOS] */ ); path = "RNTester-macOSUnitTests"; sourceTree = ""; @@ -1350,6 +1353,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + FAB526460000000000000001 /* RCTFabricNativePropsTests.mm in Sources */, /* [macOS] */ AC73FCEF29B1318B0003586F /* RCTAnimationUtilsTests.m in Sources */, AC73FD0729B131DA0003586F /* RCTUIManagerTests.m in Sources */, AC73FCF729B131A20003586F /* RCTEventDispatcherTests.m in Sources */, From e3492a9023fc1d066046ea05f341c8b99404c039 Mon Sep 17 00:00:00 2001 From: Jason Morse Date: Thu, 12 Nov 2026 22:35:03 +0000 Subject: [PATCH 2/4] fix(0.81, fabric): synchronize native props across shadow node clones Backport MIT-licensed react/react-native commit 923e7ddcaf4d2de45ca7dedafbb84c6b87dbffc4 by OrfeasZ (#52646), preserving upstream copyright and license headers. Use one family-owned mutex for both UIManager writers and ShadowNode cloning, releasing it before parsing, descriptor callbacks and commits. Retain the 0.81 context-container API, update its existing private C++ API snapshot and add a patch Changeset. Rebuild all native consumers because ShadowNodeFamily layout changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 33ea5c72-8bbd-448d-aa21-c9b99dd03c96 --- .changeset/fabric-native-props-sync.md | 7 ++ .../react/renderer/core/ShadowNode.cpp | 48 +++++--- .../react/renderer/core/ShadowNodeFamily.h | 2 + .../react/renderer/uimanager/UIManager.cpp | 115 ++++++++++-------- private/cxx-public-api/ReactNativeCPP.api | 1 + 5 files changed, 101 insertions(+), 72 deletions(-) create mode 100644 .changeset/fabric-native-props-sync.md diff --git a/.changeset/fabric-native-props-sync.md b/.changeset/fabric-native-props-sync.md new file mode 100644 index 000000000000..8168de9cd291 --- /dev/null +++ b/.changeset/fabric-native-props-sync.md @@ -0,0 +1,7 @@ +--- +"react-native-macos": patch +--- + + + +Backport upstream Fabric native-props synchronization to prevent crashes when native props are updated while shadow nodes are cloned. diff --git a/packages/react-native/ReactCommon/react/renderer/core/ShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/core/ShadowNode.cpp index a3af28d8ed7b..bee9a1ec4b98 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/ShadowNode.cpp @@ -136,32 +136,42 @@ ShadowNode::ShadowNode( } } +// [macOS Backport react/react-native@923e7ddcaf4d (#52646). std::shared_ptr ShadowNode::clone( const ShadowNodeFragment& fragment) const { const auto& family = *family_; const auto& componentDescriptor = family.componentDescriptor_; - if (family.nativeProps_DEPRECATED != nullptr) { - auto propsParserContext = PropsParserContext{family_->getSurfaceId(), {}}; - if (fragment.props == ShadowNodeFragment::propsPlaceholder()) { - // Clone existing `props_` with `family.nativeProps_DEPRECATED` to apply - // previously set props via `setNativeProps` API. - auto props = componentDescriptor.cloneProps( - propsParserContext, props_, RawProps(*family.nativeProps_DEPRECATED)); - auto clonedNode = componentDescriptor.cloneShadowNode( - *this, - {.props = props, - .children = fragment.children, - .state = fragment.state}); - return clonedNode; - } else { - // TODO: We might need to merge fragment.priops with - // `family.nativeProps_DEPRECATED`. - return componentDescriptor.cloneShadowNode(*this, fragment); + + std::optional propsOverride; + { + std::lock_guard lock(family.nativePropsMutex); + if (family.nativeProps_DEPRECATED != nullptr) { + if (fragment.props == ShadowNodeFragment::propsPlaceholder()) { + propsOverride.emplace(*family.nativeProps_DEPRECATED); + } else { + // TODO: We might need to merge fragment.props with + // `family.nativeProps_DEPRECATED`. + } } - } else { - return componentDescriptor.cloneShadowNode(*this, fragment); } + + if (propsOverride) { + // Clone existing `props_` with `family.nativeProps_DEPRECATED` to + // apply previously set props via `setNativeProps` API. The parsed + // result escapes the lock so the rest of the clone work runs + // unblocked. + auto propsParserContext = PropsParserContext{family_->getSurfaceId(), {}}; + return componentDescriptor.cloneShadowNode( + *this, + {.props = componentDescriptor.cloneProps( + propsParserContext, props_, std::move(*propsOverride)), + .children = fragment.children, + .state = fragment.state}); + } + + return componentDescriptor.cloneShadowNode(*this, fragment); } +// macOS] ContextContainer::Shared ShadowNode::getContextContainer() const { return family_->componentDescriptor_.getContextContainer(); diff --git a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h index 838560895287..6fd6a45dc26f 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h @@ -8,6 +8,7 @@ #pragma once #include +#include // [macOS] Backport upstream #52646. #include #include @@ -116,6 +117,7 @@ class ShadowNodeFamily final : public jsi::NativeState { * architecture and will be removed in the future. */ mutable std::unique_ptr nativeProps_DEPRECATED; + mutable std::mutex nativePropsMutex; // [macOS] Backport upstream #52646. /** * @return tag for the ShadowNodeFamily. diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp index edee8ac36bca..39c248e2f147 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp @@ -103,6 +103,7 @@ std::shared_ptr UIManager::createNode( return shadowNode; } +// [macOS Backport react/react-native@923e7ddcaf4d (#52646). std::shared_ptr UIManager::cloneNode( const ShadowNode& shadowNode, const ShadowNode::SharedListOfShared& children, @@ -115,49 +116,51 @@ std::shared_ptr UIManager::cloneNode( auto& componentDescriptor = shadowNode.getComponentDescriptor(); auto& family = shadowNode.getFamily(); - auto props = ShadowNodeFragment::propsPlaceholder(); + auto props = ShadowNodeFragment::propsPlaceholder(); if (!rawProps.isEmpty()) { - if (family.nativeProps_DEPRECATED != nullptr) { - // 1. update the nativeProps_DEPRECATED props. - // - // In this step, we want the most recent value for the props - // managed by setNativeProps. - // Values in `rawProps` patch (take precedence over) - // `nativeProps_DEPRECATED`. For example, if both - // `nativeProps_DEPRECATED` and `rawProps` contain key 'A'. - // Value from `rawProps` overrides what was previously in - // `nativeProps_DEPRECATED`. Notice that the `nativeProps_DEPRECATED` - // patch will not get more props from `rawProps`: if the key is not - // present in `nativeProps_DEPRECATED`, it will not be added. - // - // The result of this operation is the new `nativeProps_DEPRECATED`. - family.nativeProps_DEPRECATED = - std::make_unique(mergeDynamicProps( - *family.nativeProps_DEPRECATED, // source - (folly::dynamic)rawProps, // patch - NullValueStrategy::Ignore)); - - // 2. Compute the final set of props. - // - // This step takes the new props handled by `setNativeProps` and - // merges them in the `rawProps` managed by React. - // The new props handled by `nativeProps` now takes precedence - // on the props handled by React, as we want to make sure that - // all the props are applied to the component. - // We use these finalProps as source of truth for the component. - auto finalProps = mergeDynamicProps( - (folly::dynamic)rawProps, // source - *family.nativeProps_DEPRECATED, // patch - NullValueStrategy::Override); - - // 3. Clone the props by using finalProps. - props = componentDescriptor.cloneProps( - propsParserContext, shadowNode.getProps(), RawProps(finalProps)); - } else { - props = componentDescriptor.cloneProps( - propsParserContext, shadowNode.getProps(), std::move(rawProps)); + std::optional finalProps; + { + std::lock_guard lock(family.nativePropsMutex); + if (family.nativeProps_DEPRECATED != nullptr) { + // 1. update the nativeProps_DEPRECATED props. + // + // In this step, we want the most recent value for the props + // managed by setNativeProps. + // Values in `rawProps` patch (take precedence over) + // `nativeProps_DEPRECATED`. For example, if both + // `nativeProps_DEPRECATED` and `rawProps` contain key 'A'. + // Value from `rawProps` overrides what was previously in + // `nativeProps_DEPRECATED`. Notice that the `nativeProps_DEPRECATED` + // patch will not get more props from `rawProps`: if the key is not + // present in `nativeProps_DEPRECATED`, it will not be added. + // + // The result of this operation is the new `nativeProps_DEPRECATED`. + family.nativeProps_DEPRECATED = + std::make_unique(mergeDynamicProps( + *family.nativeProps_DEPRECATED, // source + (folly::dynamic)rawProps, // patch + NullValueStrategy::Ignore)); + + // 2. Compute the final set of props. + // + // This step takes the new props handled by `setNativeProps` and + // merges them in the `rawProps` managed by React. + // The new props handled by `nativeProps` now takes precedence + // on the props handled by React, as we want to make sure that + // all the props are applied to the component. + // We use these finalProps as source of truth for the component. + finalProps = mergeDynamicProps( + (folly::dynamic)rawProps, // source + *family.nativeProps_DEPRECATED, // patch + NullValueStrategy::Override); + } } + + props = componentDescriptor.cloneProps( + propsParserContext, + shadowNode.getProps(), + finalProps ? RawProps(std::move(*finalProps)) : std::move(rawProps)); } auto clonedShadowNode = componentDescriptor.cloneShadowNode( @@ -170,6 +173,7 @@ std::shared_ptr UIManager::cloneNode( return clonedShadowNode; } +// macOS] void UIManager::appendChild( const std::shared_ptr& parentShadowNode, @@ -426,20 +430,25 @@ void UIManager::setNativeProps_DEPRECATED( const std::shared_ptr& shadowNode, RawProps rawProps) const { auto& family = shadowNode->getFamily(); - if (family.nativeProps_DEPRECATED) { - // Values in `rawProps` patch (take precedence over) - // `nativeProps_DEPRECATED`. For example, if both `nativeProps_DEPRECATED` - // and `rawProps` contain key 'A'. Value from `rawProps` overrides what was - // previously in `nativeProps_DEPRECATED`. - family.nativeProps_DEPRECATED = - std::make_unique(mergeDynamicProps( - *family.nativeProps_DEPRECATED, - (folly::dynamic)rawProps, - NullValueStrategy::Override)); - } else { - family.nativeProps_DEPRECATED = - std::make_unique((folly::dynamic)rawProps); + // [macOS Backport react/react-native@923e7ddcaf4d (#52646). + { + std::lock_guard lock(family.nativePropsMutex); + if (family.nativeProps_DEPRECATED) { + // Values in `rawProps` patch (take precedence over) + // `nativeProps_DEPRECATED`. For example, if both `nativeProps_DEPRECATED` + // and `rawProps` contain key 'A'. Value from `rawProps` overrides what + // was previously in `nativeProps_DEPRECATED`. + family.nativeProps_DEPRECATED = + std::make_unique(mergeDynamicProps( + *family.nativeProps_DEPRECATED, + (folly::dynamic)rawProps, + NullValueStrategy::Override)); + } else { + family.nativeProps_DEPRECATED = + std::make_unique((folly::dynamic)rawProps); + } } + // macOS] shadowTreeRegistry_.visit( family.getSurfaceId(), [&](const ShadowTree& shadowTree) { diff --git a/private/cxx-public-api/ReactNativeCPP.api b/private/cxx-public-api/ReactNativeCPP.api index 8c2f51b8e1b5..10b0052a06e4 100644 --- a/private/cxx-public-api/ReactNativeCPP.api +++ b/private/cxx-public-api/ReactNativeCPP.api @@ -28449,6 +28449,7 @@ class ShadowNodeFamily final : public jsi::NativeState { void setMounted() const; void dispatchRawState(StateUpdate&& stateUpdate) const; mutable std::unique_ptr nativeProps_DEPRECATED; + mutable std::mutex nativePropsMutex; Tag getTag() const; jsi::Value getInstanceHandle(jsi::Runtime& runtime) const; InstanceHandle::Shared getInstanceHandle() const; From 205d877c999ad1b85c27956dbea1f84bd0454422 Mon Sep 17 00:00:00 2001 From: Jason Morse Date: Thu, 12 Nov 2026 23:02:19 +0000 Subject: [PATCH 3/4] fix(0.81, release): resolve versions from stable dist-tag Correct the pre-existing 0.81 NPM dry-run blocker after 0.83 became latest. The unchanged branch-aware prepublish rules require 0.81-stable for an older minor. Match that existing rule rather than bypassing validation or altering publication policy. The installed Nx registry resolver now reads 0.81.9 for both react-native-macos and @react-native-macos/virtualized-lists. The original validator failed against unchanged baseline metadata; the corrected validator and actual resolver pass without authentication, versioning or publishing. Only nx.json changes; renderer/test commits reviewed through e3492a9023 remain unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 33ea5c72-8bbd-448d-aa21-c9b99dd03c96 --- nx.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nx.json b/nx.json index 06f7fc86f307..6b2e8c592e8e 100644 --- a/nx.json +++ b/nx.json @@ -21,7 +21,7 @@ "versionActionsOptions": { "currentVersionResolver": "registry", "currentVersionResolverMetadata": { - "tag": "latest" + "tag": "0.81-stable" } }, "useLegacyVersioning": false From a7b0f00152371674043cd6c11f633f9346ec08ef Mon Sep 17 00:00:00 2001 From: Jason Morse Date: Fri, 13 Nov 2026 00:01:10 +0000 Subject: [PATCH 4/4] fix(0.81, release): queue the Fabric backport with Nx Address the Opus review finding that 0.81-stable has Nx version plans, not Changesets. Use the existing fixed release-group convention and remove the inert Changeset. No version is published or bumped by this commit. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 33ea5c72-8bbd-448d-aa21-c9b99dd03c96 --- .changeset/fabric-native-props-sync.md | 7 ------- .nx/version-plans/version-plan-1794527878844.md | 5 +++++ 2 files changed, 5 insertions(+), 7 deletions(-) delete mode 100644 .changeset/fabric-native-props-sync.md create mode 100644 .nx/version-plans/version-plan-1794527878844.md diff --git a/.changeset/fabric-native-props-sync.md b/.changeset/fabric-native-props-sync.md deleted file mode 100644 index 8168de9cd291..000000000000 --- a/.changeset/fabric-native-props-sync.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -"react-native-macos": patch ---- - - - -Backport upstream Fabric native-props synchronization to prevent crashes when native props are updated while shadow nodes are cloned. diff --git a/.nx/version-plans/version-plan-1794527878844.md b/.nx/version-plans/version-plan-1794527878844.md new file mode 100644 index 000000000000..10bf92529212 --- /dev/null +++ b/.nx/version-plans/version-plan-1794527878844.md @@ -0,0 +1,5 @@ +--- +__default__: patch +--- + +Fix Fabric native-props synchronization during concurrent rendering and window resize.