Skip to content

Commit 9342430

Browse files
michalmakapull[bot]
authored andcommitted
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 ff5ac2f commit 9342430

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
@@ -351,6 +351,11 @@ CommitStatus ShadowTree::tryCommit(
351351
newRootShadowNode = delegate_.shadowTreeWillCommit(
352352
*this, oldRootShadowNode, newRootShadowNode);
353353

354+
if (!newRootShadowNode ||
355+
(commitOptions.shouldYield && commitOptions.shouldYield())) {
356+
return CommitStatus::Cancelled;
357+
}
358+
354359
// Layout nodes.
355360
std::vector<LayoutableShadowNode const *> affectedLayoutableNodes{};
356361
affectedLayoutableNodes.reserve(1024);
@@ -368,17 +373,16 @@ CommitStatus ShadowTree::tryCommit(
368373
// Updating `currentRevision_` in unique manner if it hasn't changed.
369374
std::unique_lock lock(commitMutex_);
370375

376+
if (commitOptions.shouldYield && commitOptions.shouldYield()) {
377+
return CommitStatus::Cancelled;
378+
}
379+
371380
if (currentRevision_.number != oldRevision.number) {
372381
return CommitStatus::Failed;
373382
}
374383

375384
auto newRevisionNumber = oldRevision.number + 1;
376385

377-
if (!newRootShadowNode ||
378-
(commitOptions.shouldYield && commitOptions.shouldYield())) {
379-
return CommitStatus::Cancelled;
380-
}
381-
382386
{
383387
std::lock_guard<std::mutex> dispatchLock(EventEmitter::DispatchMutex());
384388

0 commit comments

Comments
 (0)