Skip to content

Only keep a cloned node's layout when its children's computed layouts match - #59984

Open
lenaic wants to merge 1 commit into
react:mainfrom
lenaic:export-D131502045
Open

lenaic wants to merge 1 commit into
react:mainfrom
lenaic:export-D131502045

Conversation

@lenaic

@lenaic lenaic commented Nov 12, 2026

Copy link
Copy Markdown

Summary:
When a host node is cloned with its children passed in (passChildrenWhenCloningPersistedNodes), YogaLayoutableShadowNode::updateYogaChildren keeps the clone's layout clean if every new child is clean and styled like the child it replaces. That misses children that are clean and styled the same but carry a different computed layout. Yoga then reuses the parent's cached layout, never visits those children, and they keep their stale layout.

Runtime shadow node reference updates produce exactly such children when <Activity> hides a subtree:

  1. The renderer commits a display: none clone H of the hidden subtree's host root V. H gets its own runtime reference; the renderer keeps V, which still holds the layout and layout cache from when it was visible.
  2. Laying out H zeroes out clones of V's children. Those clones inherit the children's runtime references, so the renderer now holds the zeroed revisions of V's children while it still holds the non-zeroed V.
  3. Any re-render inside the subtree clones those zeroed children and then V with the new children. Every check passes, so V's clone keeps V's cached layout.
  4. When the subtree is revealed, Yoga reuses that cache and the content stays at 0x0.

With the children appended one by one instead, the append always dirties the parent, so this only shows up with the flag on.

Also require each new child's computed size and position to match the child it replaces before keeping the clone clean. A parent's cached layout is only valid for the layouts its children had when it was computed, so this is the condition the optimization relied on. Unchanged children still match, so re-renders that do not change layout keep the layout clean.

Changelog: [General][Fixed] - Fix content laid out at zero size after revealing an <Activity> subtree when children are passed into clones

Differential Revision: D131502045

… match

Summary:
When a host node is cloned with its children passed in (`passChildrenWhenCloningPersistedNodes`), `YogaLayoutableShadowNode::updateYogaChildren` keeps the clone's layout clean if every new child is clean and styled like the child it replaces. That misses children that are clean and styled the same but carry a different computed layout. Yoga then reuses the parent's cached layout, never visits those children, and they keep their stale layout.

Runtime shadow node reference updates produce exactly such children when `<Activity>` hides a subtree:

1. The renderer commits a `display: none` clone H of the hidden subtree's host root V. H gets its own runtime reference; the renderer keeps V, which still holds the layout and layout cache from when it was visible.
2. Laying out H zeroes out clones of V's children. Those clones inherit the children's runtime references, so the renderer now holds the zeroed revisions of V's children while it still holds the non-zeroed V.
3. Any re-render inside the subtree clones those zeroed children and then V with the new children. Every check passes, so V's clone keeps V's cached layout.
4. When the subtree is revealed, Yoga reuses that cache and the content stays at 0x0.

With the children appended one by one instead, the append always dirties the parent, so this only shows up with the flag on.

Also require each new child's computed size and position to match the child it replaces before keeping the clone clean. A parent's cached layout is only valid for the layouts its children had when it was computed, so this is the condition the optimization relied on. Unchanged children still match, so re-renders that do not change layout keep the layout clean.

Changelog: [General][Fixed] - Fix content laid out at zero size after revealing an `<Activity>` subtree when children are passed into clones

Differential Revision: D131502045
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 12, 2026
@meta-codesync

meta-codesync Bot commented Nov 12, 2026

Copy link
Copy Markdown

@lenaic has exported this pull request. If you are a Meta employee, you can view the originating Diff in D131502045.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant