Skip to content

Commit 851d59a

Browse files
Nick Lefevermeta-codesync[bot]
authored andcommitted
Add fantom test for syncOnCommit with passChildrenWhenCloning bug fix (#54264)
Summary: Pull Request resolved: #54264 Implementing a fantom test covering the correct update of runtime shadow node references when using passChildrenWhenCloningPersistedNodes combined with syncOnCommit. Changelog: [Internal] Reviewed By: sbuggay Differential Revision: D85437783 fbshipit-source-id: adad786e293c1acfe13e3a07ffb210dec0c17292
1 parent 91d5e99 commit 851d59a

File tree

1 file changed

+181
-0
lines changed

1 file changed

+181
-0
lines changed
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @fantom_flags updateRuntimeShadowNodeReferencesOnCommit:true
8+
* @fantom_react_fb_flags passChildrenWhenCloningPersistedNodes:true
9+
* @flow strict-local
10+
* @format
11+
*/
12+
13+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
14+
15+
import * as Fantom from '@react-native/fantom';
16+
import * as React from 'react';
17+
import {View} from 'react-native';
18+
19+
describe('Render updates with passChildrenWhenCloningPersistedNodes', () => {
20+
it('updates the runtime shadow node reference correctly when using sync on commit', () => {
21+
const root = Fantom.createRoot();
22+
23+
// Initial render setting to row items next to each other
24+
Fantom.runTask(() => {
25+
root.render(
26+
<View nativeID="parent" style={{flex: 1, flexDirection: 'row'}}>
27+
<View
28+
nativeID="initial-child-1"
29+
key="1"
30+
style={{width: 100, height: 32}}
31+
/>
32+
<View
33+
nativeID="initial-child-2"
34+
key="2"
35+
style={{width: 100, height: 32}}>
36+
<View nativeID="sub-child-2-1" key="1" />
37+
</View>
38+
</View>,
39+
);
40+
});
41+
42+
// Insert new items on the row between the previous two items
43+
Fantom.runTask(() => {
44+
root.render(
45+
<View nativeID="parent" style={{flex: 1, flexDirection: 'row'}}>
46+
<View
47+
nativeID="initial-child-1"
48+
key="1"
49+
style={{width: 100, height: 32}}
50+
/>
51+
<View
52+
nativeID="inserted-child-1"
53+
key="3"
54+
style={{width: 100, height: 32}}
55+
/>
56+
<View
57+
nativeID="initial-child-2"
58+
key="2"
59+
style={{width: 100, height: 32}}>
60+
<View nativeID="sub-child-2-1" key="1" />
61+
</View>
62+
<View
63+
nativeID="inserted-child-2"
64+
key="4"
65+
style={{width: 100, height: 32}}
66+
/>
67+
<View
68+
nativeID="inserted-child-3"
69+
key="5"
70+
style={{width: 100, height: 32}}
71+
/>
72+
</View>,
73+
);
74+
});
75+
76+
// Update a prop on the children of the original row item to force a clone
77+
Fantom.runTask(() => {
78+
root.render(
79+
<View nativeID="parent" style={{flex: 1, flexDirection: 'row'}}>
80+
<View
81+
nativeID="initial-child-1"
82+
key="1"
83+
style={{width: 100, height: 32}}
84+
/>
85+
<View
86+
nativeID="inserted-child-1"
87+
key="3"
88+
style={{width: 100, height: 32}}
89+
/>
90+
<View
91+
nativeID="initial-child-2"
92+
key="2"
93+
style={{width: 100, height: 32}}>
94+
<View
95+
nativeID="sub-child-2-1"
96+
key="1"
97+
testID="prop-change-to-force-clone"
98+
/>
99+
</View>
100+
<View
101+
nativeID="inserted-child-2"
102+
key="4"
103+
style={{width: 100, height: 32}}
104+
/>
105+
<View
106+
nativeID="inserted-child-3"
107+
key="5"
108+
style={{width: 100, height: 32}}
109+
/>
110+
</View>,
111+
);
112+
});
113+
114+
// The row items should all be layed out next to each other
115+
expect(
116+
root
117+
.getRenderedOutput({
118+
includeLayoutMetrics: true,
119+
props: ['layoutMetrics-frame', 'nativeID'],
120+
})
121+
.toJSON(),
122+
).toEqual({
123+
type: 'View',
124+
props: {
125+
'layoutMetrics-frame': '{x:0,y:0,width:390,height:844}',
126+
nativeID: 'parent',
127+
},
128+
children: [
129+
{
130+
type: 'View',
131+
props: {
132+
'layoutMetrics-frame': '{x:0,y:0,width:100,height:32}',
133+
nativeID: 'initial-child-1',
134+
},
135+
children: [],
136+
},
137+
{
138+
type: 'View',
139+
props: {
140+
'layoutMetrics-frame': '{x:100,y:0,width:100,height:32}',
141+
nativeID: 'inserted-child-1',
142+
},
143+
children: [],
144+
},
145+
{
146+
type: 'View',
147+
props: {
148+
'layoutMetrics-frame': '{x:200,y:0,width:100,height:32}',
149+
nativeID: 'initial-child-2',
150+
},
151+
children: [
152+
{
153+
type: 'View',
154+
props: {
155+
'layoutMetrics-frame': '{x:0,y:0,width:100,height:0}',
156+
nativeID: 'sub-child-2-1',
157+
},
158+
children: [],
159+
},
160+
],
161+
},
162+
{
163+
type: 'View',
164+
props: {
165+
'layoutMetrics-frame': '{x:300,y:0,width:100,height:32}',
166+
nativeID: 'inserted-child-2',
167+
},
168+
children: [],
169+
},
170+
{
171+
type: 'View',
172+
props: {
173+
'layoutMetrics-frame': '{x:400,y:0,width:100,height:32}',
174+
nativeID: 'inserted-child-3',
175+
},
176+
children: [],
177+
},
178+
],
179+
});
180+
});
181+
});

0 commit comments

Comments
 (0)