Skip to content

Commit 5f503b8

Browse files
michalmakaLuna Wei
authored and
Luna Wei
committed
Restore checking shadow tree commit cancellation after commit hook execution (#38715)
Summary: Hello! This PR is a fix for one merged some time ago (#36216). In the PR check for `nullptr` value of `newRootShadowNode` just after performing commit hooks was overlooked. This PR restores previous behaviour of conditional commit cancellation after commit hook execution. ## Changelog: [INTERNAL] [FIXED] - Restore checking shadow tree commit cancellation after commit hook execution Pull Request resolved: #38715 Test Plan: Just register a commit hook that return `nullptr`. In that case current code crashes due to `nullptr` dereference. Reviewed By: sammy-SC Differential Revision: D47972245 Pulled By: ryancat fbshipit-source-id: 7599ad11ed4b2dcaf25e53f676ec4530e37410d5
1 parent 4f8c87c commit 5f503b8

File tree

1 file changed

+9
-5
lines changed
  • packages/react-native/ReactCommon/react/renderer/mounting

1 file changed

+9
-5
lines changed

packages/react-native/ReactCommon/react/renderer/mounting/ShadowTree.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ CommitStatus ShadowTree::tryCommit(
355355
newRootShadowNode = delegate_.shadowTreeWillCommit(
356356
*this, oldRootShadowNode, newRootShadowNode);
357357

358+
if (!newRootShadowNode ||
359+
(commitOptions.shouldYield && commitOptions.shouldYield())) {
360+
return CommitStatus::Cancelled;
361+
}
362+
358363
// Layout nodes.
359364
std::vector<LayoutableShadowNode const *> affectedLayoutableNodes{};
360365
affectedLayoutableNodes.reserve(1024);
@@ -372,17 +377,16 @@ CommitStatus ShadowTree::tryCommit(
372377
// Updating `currentRevision_` in unique manner if it hasn't changed.
373378
std::unique_lock lock(commitMutex_);
374379

380+
if (commitOptions.shouldYield && commitOptions.shouldYield()) {
381+
return CommitStatus::Cancelled;
382+
}
383+
375384
if (currentRevision_.number != oldRevision.number) {
376385
return CommitStatus::Failed;
377386
}
378387

379388
auto newRevisionNumber = oldRevision.number + 1;
380389

381-
if (!newRootShadowNode ||
382-
(commitOptions.shouldYield && commitOptions.shouldYield())) {
383-
return CommitStatus::Cancelled;
384-
}
385-
386390
{
387391
std::lock_guard<std::mutex> dispatchLock(EventEmitter::DispatchMutex());
388392

0 commit comments

Comments
 (0)