diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/ShadowTree.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/ShadowTree.cpp index 1ded30dcfdacb4..ccacefe77d592c 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/ShadowTree.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/ShadowTree.cpp @@ -351,6 +351,11 @@ CommitStatus ShadowTree::tryCommit( newRootShadowNode = delegate_.shadowTreeWillCommit( *this, oldRootShadowNode, newRootShadowNode); + if (!newRootShadowNode || + (commitOptions.shouldYield && commitOptions.shouldYield())) { + return CommitStatus::Cancelled; + } + // Layout nodes. std::vector affectedLayoutableNodes{}; affectedLayoutableNodes.reserve(1024); @@ -368,17 +373,16 @@ CommitStatus ShadowTree::tryCommit( // Updating `currentRevision_` in unique manner if it hasn't changed. std::unique_lock lock(commitMutex_); + if (commitOptions.shouldYield && commitOptions.shouldYield()) { + return CommitStatus::Cancelled; + } + if (currentRevision_.number != oldRevision.number) { return CommitStatus::Failed; } auto newRevisionNumber = oldRevision.number + 1; - if (!newRootShadowNode || - (commitOptions.shouldYield && commitOptions.shouldYield())) { - return CommitStatus::Cancelled; - } - { std::lock_guard dispatchLock(EventEmitter::DispatchMutex());