Skip to content

Commit 0769ddf

Browse files
Nick Lefeverfacebook-github-bot
Nick Lefever
authored andcommitted
Add documentation for passChildrenWhenCloning feature (#51447)
Summary: Pull Request resolved: #51447 Changelog: [Internal] Document how the `passChildrenWhenCloningPersistedNodes` feature works. Reviewed By: rshest Differential Revision: D74961913 fbshipit-source-id: 6f412de36acc233a6bdf3d59548035ad884264a8
1 parent b2775a4 commit 0769ddf

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

__docs__/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ TODO: Explain the different components of React Native at a high level.
4646
- Events
4747
- Shadow Tree Lifecycle
4848
- [Runtime Shadow Node Reference Update](../packages/react-native/ReactCommon/react/renderer/core/__docs__/RSNRU.md)
49+
- [passChildrenWhenCloningPersistedNodes](../packages/react-native/ReactCommon/react/renderer/core/__docs__/passChildrenWhenCloning.md)
4950
- Layout
5051
- Mounting
5152
- Native Modules / TurboModules

packages/react-native/ReactCommon/react/renderer/core/__docs__/passChildrenWhenCloning.excalidraw.svg

Lines changed: 2 additions & 0 deletions
Loading
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Runtime Shadow Node Reference Updates
2+
3+
[🏠 Home](../../../../../../../__docs__/README.md)
4+
5+
The `passChildrenWhenCloningPersistedNodes` feature improves rendering
6+
performance for use cases where cloning of Shadow Nodes holding a large number
7+
of children is frequent. A typical example of these are ScrollView components
8+
holding large lists. The feature improves layout performance by reducing the
9+
need to invalidate the layout information held by the cloned Shadow Node.
10+
11+
## 🚀 Usage
12+
13+
The features is controlled by the `passChildrenWhenCloningPersistedNodes` flag
14+
defined in the `ReactNativeInternalFeatureFlags` file. Seeting the feature flag
15+
before the React renderer is initialized will enable the feature.
16+
17+
## 📐 Design
18+
19+
![passChildrenWhenCloningPersistedNodes in React Native](./passChildrenWhenCloning.excalidraw.svg)
20+
21+
When the React renderer needs to clone a node that represents a host component
22+
and thus has a corresponding ShadowNode instance, the process follows these
23+
steps:
24+
25+
- Clone the ShadowNode
26+
- Traverse the node's descendants to find all first level host components
27+
- Whenever a host component is seen, append it to the newly cloned ShadowNode
28+
instance
29+
30+
Most ShadowNode instances hold layout data and are represented by a
31+
YogaLayoutableShadowNode. These nodes are responsible for keeping the yoga tree
32+
updated and holding the final layout data for the native view that the
33+
ShadowNode represents.
34+
35+
Any modification of a YogaLayoutableShadowNode will mark the node as dirty and
36+
requiring layout when committed. Appending a child node to a
37+
YogaLayoutableShadowNode is considered as a modification. Meaning that whenever
38+
the React renderer needs to clone a ShadowNode that has direct children, it will
39+
be marked as having a dirty layout when the children will be appended back to
40+
the cloned instance.
41+
42+
The `passChildrenWhenCloningPersistedNodes` feature collects all children that
43+
need to be appended to the ShadowNode after cloning in a set. This set is being
44+
passed to the ShadowNode clone call which in turn will append back the nodes
45+
directly during the cloning. This removes the need to append the children one by
46+
one after cloning and bypasses the node dirtying that is involved with this type
47+
of mutation.
48+
49+
The clone implementation of the YogaLayoutableShadowNode will compare the
50+
previous set of children with the new set. If both sets have the same size and
51+
each node has equivalent styling, the cloned node is not being dirtied for
52+
layout. This allows for improving the layout data re-use on subsequent renders.

0 commit comments

Comments
 (0)