Repository navigation
Apply UIManager::updateShadowTree on top of the tree it commits to - #60527
Open
leeseonghyun21 wants to merge 1 commit into
Open
leeseonghyun21 wants to merge 1 commit into
leeseonghyun21 wants to merge 1 commit into
Conversation
Signed-off-by: leeseonghyun21 <33210765+leeseonghyun21@users.noreply.github.com>
leeseonghyun21
force-pushed
the
fix/update-shadow-tree-current-root
branch
from
December 4, 2026 03:14
f5c7199 to
4541548
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
UIManager::updateShadowTreeclones the nodes it updates from a snapshot of the shadow tree (shadowTree.getCurrentRevision()), then commits with a transaction that ignores the root it receives and returns that clone:shadowTree.commit( [rootNode = it->second](const RootShadowNode&) -> RootShadowNode::Unshared { return std::static_pointer_cast<RootShadowNode>(rootNode); }, {});If another thread commits between the snapshot and this commit, the commit is silently reverted.
ShadowTree::commitcannot catch it: when the revision check fails, it runs the transaction again, and the transaction returns the same stale tree.The commit that gets lost most visibly is
SurfaceHandler::constraintLayoutafter the surface is resized (rotation, fold/unfold, split screen, window resize). The surface then keeps its previous size for good:SurfaceHandlerhas already stored the new constraints, so when the same size arrives again it returns early (parameters_.layoutConstraints == layoutConstraints) and never commits it. The app stays drawn at the old size, for example the unfolded layout in the top-left quarter of a folded screen, until the size changes again. Native state updates committed from the UI thread in that window are reverted in the same way.Who calls
updateShadowTree:NativeAnimatedNodesManagerProvider, throughMergedValueDispatcher): it commits layout props, and the final props of every finished animation (forceFabricCommit). Since Promote C++ Native Animated to stable (#59936) #59936 madecxxNativeAnimatedEnabledstable, this is every app that runs auseNativeDriveranimation, unlessuseSharedAnimatedBackendis on.react-native-unistyles3, which callsupdateShadowTreein response to the same size change. In a scripted loop (screen off, fold, screen on) on a Galaxy Z Fold, the app stayed stuck at the unfolded size in 7 of 18 runs with Unistyles 3.1.1 and 6 of 144 runs with 3.5.3. We have shipped a patch with the same effect (carrying the current constraints over in this transaction) since then. Unistyles worked around it on its side in fix: keep new layout constraints when committing style updates jpudysz/react-native-unistyles#1357.This PR moves the cloning into the commit transaction, the way
AnimationBackendalready commits animated props: the walk over the snapshot only finds the families of the tags, and the transaction clones those families and their ancestors withShadowNode::cloneMultiplefrom the root it receives. A retried transaction now clones the newer tree, so concurrent commits are kept. Props are also cloned from the current node instead of the snapshot node.This also drops the hand-written ancestor bookkeeping (
ShadowNodeUpdateInfo,addAncestorsToUpdateList), whichcloneMultipledoes for us.Changelog:
[GENERAL] [FIXED] - Fix
UIManager::updateShadowTree(used by C++ Native Animated) reverting commits made concurrently, such as the new surface size after a rotation or foldTest Plan:
New gtest
UIManagerUpdateShadowTreeTest(ReactCommon/react/renderer/uimanager/tests). Two of its tests interleave a commit deterministically: a commit hook that, for the commit made byupdateShadowTree, commits from another thread and waits for it. That is the state the transaction is in when a UI-thread commit lands while it runs: the revision check fails and the transaction runs again on the newer tree.KeepsLayoutConstraintsCommittedConcurrently: the concurrent commit is whatSurfaceHandler::constraintLayoutcommits on resize (500x800 → 800x500).KeepsNodesCommittedConcurrently: the concurrent commit changes a sibling's props.Built and run with the OSS ReactCommon test runner (
./gradlew :private:react-native-fantom:buildReactCommonTests, then thereact_renderer_uimanager_testsbinary), macOS arm64:mainUpdatesPropsIgnoresTagsNotInTreeKeepsLayoutConstraintsCommittedConcurrentlyKeepsNodesCommittedConcurrentlynativeIDback to"initial"Regression checks with this PR:
react_renderer_uimanager_tests(16),react_renderer_animated_tests(28),react_renderer_mounting_tests(37): all pass.yarn fantom packages/react-native/Libraries/Animated packages/react-native/src/private/animated: 19 suites, 376 tests pass (3 benchmark suites skipped).RNTester on a Pixel 9 Pro Fold emulator (API 36, default feature flags, so the final props of every finished
useNativeDriveranimation are committed throughupdateShadowTree): a Playground screen with 200Animated.Views whose native-driven opacity animations restart every 16–64 ms, rotated 30 times. With this PR the root view followed all 31 size changes and the animations kept running. The race did not show by hand onmaineither (0 of 31), so the gtests above are the reproduction.🤖 Generated with Claude Code