Repository navigation
Conversation
zeroOutLayoutRecursively runs for every display: none child on every layout pass of its parent, and called cloneChildrenIfNeeded() at every level of the hidden subtree. When the subtree is shared with an earlier tree, the clone callback fired for every hidden node on every pass, even though zeroing it out again changed nothing. In React Native each of those callbacks is a ShadowNode clone. Skip cloning and recursing into children whose subtree is already zeroed out. configVersion is ignored in that check: it only validates the layout cache, which is empty after zeroing out, and embedders such as React Native set it again when they give a cloned node its config. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shubh73
force-pushed
the
skip-recloning-zeroed-display-none
branch
from
October 31, 2026 02:10
41c43d5 to
8f6d015
Compare
shubh73
added a commit
to shubh73/react-native
that referenced
this pull request
Oct 31, 2026
Tests that a hidden subtree isn't cloned on every commit that lays out its parent, through React commits and setNativeProps, and that hidden screens lay out the same as never-hidden ones once shown again. The second test depends on react/yoga#2055 and fails until that change is synced into the vendored copy of Yoga. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Probably related, although I don't think they're duplicates? react/react-native#59302 |
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
zeroOutLayoutRecursivelyruns for everydisplay: nonechild on every layout pass of its parent, and callscloneChildrenIfNeeded()at every level of the hidden subtree. When that subtree is shared with an earlier tree, the clone callback fires for every hidden node on every pass, even though zeroing it out again changes nothing.In React Native each of those callbacks is a ShadowNode clone, and Fabric's
layout()doesn't descend intodisplay: none, so nothing settles them. Every commit that lays out the parent of a hidden view clones everything under it again. Apps that keep screens mounted withdisplay: none, e.g. under<Activity mode="hidden">, pay this on every update for every hidden screen.This skips cloning and recursing into children whose subtree is already zeroed out:
hasNewLayoutis set and the layout equals a zeroed outLayoutResults, all the way down. Children are only cloned once one of them needs zeroing out, e.g. after a node was added inside a hidden subtree. Layout results are unchanged.configVersionis ignored in that comparison. It only validates the layout cache, which is empty after zeroing out, and embedders set it again when they give a cloned node a config. React Native does this for every clone, so without it the check would never match there.Some notes for review:
LayoutResults::operator==skips the generation-tagged caches,computedAutoMinMainSizeand the raw dimensions. That's fine here: laying out or measuring a node writes fields it does compare (cachedLayout, the cached measurements), so a node only matches if nothing has laid it out since it was zeroed out.hasNewLayoutset underdisplay: nonenodes, as React Native does. An embedder that clears it (relayout_clones_display_none_subtree_without_new_layout) gets the old behaviour.cloneChildrenIfNeededstill eagerly clonesdisplay: contentschildren of a cloned node, so those are cloned one level down. Anything deeper isn't.React Native side: react/react-native#59706, which adds a Fantom test on top of this.
Changelog: [General][Fixed] - Fix
display: nonesubtrees being cloned on every layout pass of their parentMetrics
OPPO CPH2667 (Android 16), React Native RNTester release build, with one visible screen and N hidden
display: nonescreens of about 500 nodes each. Each value is the extra time per update to the visible screen compared with N = 0, as the median of three alternating rounds of 500 updates. The range across rounds is in brackets.What's left is mostly in React Native, outside Yoga.
Test plan
Added six tests to
tests/YGPersistentNodeCloningTest.cpp, using its clone callback harness:relayout_does_not_clone_zeroed_out_display_none_subtreeadding_node_to_display_none_subtree_does_not_clone_zeroed_out_subtreesrelayout_does_not_clone_display_contents_in_display_none_subtreerelayout_does_not_clone_display_none_subtree_after_config_is_reapplied: clones part of a hidden subtree and callsYGNodeSetConfigon each clone, as React Native does.showing_display_none_subtree_matches_never_hidden_layoutrelayout_clones_display_none_subtree_without_new_layoutWithout the change in
CalculateLayout.cpp, the first four fail and the last two pass../yogatests: 877 tests pass onmain. With this change, all 883 pass. With only the tests, 879 pass and those 4 fail. I built withCXXFLAGS=-Wno-error=character-conversion, because googletest 1.12.1 doesn't build under-Werrorwith Apple clang 21 (gtest-printers.h).yarn format-check-cppandyarn lintpass.🤖 Generated with Claude Code