@@ -178,39 +178,44 @@ import {
178
178
} from './ReactFiberTracingMarkerComponent' ;
179
179
import { suspendCommit } from './ReactFiberThenable' ;
180
180
181
+ /**
182
+ * Tag the fiber with an update effect. This turns a Placement into
183
+ * a PlacementAndUpdate.
184
+ */
181
185
function markUpdate ( workInProgress : Fiber ) {
182
- // Tag the fiber with an update effect. This turns a Placement into
183
- // a PlacementAndUpdate.
184
186
workInProgress . flags |= Update ;
185
187
}
186
188
187
189
function markRef ( workInProgress : Fiber ) {
188
190
workInProgress . flags |= Ref | RefStatic ;
189
191
}
190
192
191
- function hadNoMutationsEffects ( current : null | Fiber , completedWork : Fiber ) {
193
+ /**
194
+ * In persistent mode, return whether this update needs to clone the subtree.
195
+ */
196
+ function doesRequireClone ( current : null | Fiber , completedWork : Fiber ) {
192
197
const didBailout = current !== null && current . child === completedWork . child ;
193
198
if ( didBailout ) {
194
- return true ;
199
+ return false ;
195
200
}
196
201
197
202
if ( ( completedWork . flags & ChildDeletion ) !== NoFlags ) {
198
- return false ;
203
+ return true ;
199
204
}
200
205
201
- // TODO: If we move the `hadNoMutationsEffects ` call after `bubbleProperties`
206
+ // TODO: If we move the `doesRequireClone ` call after `bubbleProperties`
202
207
// then we only have to check the `completedWork.subtreeFlags`.
203
208
let child = completedWork . child ;
204
209
while ( child !== null ) {
205
210
if (
206
211
( child . flags & MutationMask ) !== NoFlags ||
207
212
( child . subtreeFlags & MutationMask ) !== NoFlags
208
213
) {
209
- return false ;
214
+ return true ;
210
215
}
211
216
child = child . sibling ;
212
217
}
213
- return true ;
218
+ return false ;
214
219
}
215
220
216
221
function appendAllChildren (
@@ -303,7 +308,6 @@ function appendAllChildren(
303
308
node = node . child ;
304
309
continue ;
305
310
}
306
- node = ( node : Fiber ) ;
307
311
if ( node === workInProgress ) {
308
312
return ;
309
313
}
@@ -400,15 +404,12 @@ function appendAllChildrenToContainer(
400
404
401
405
function updateHostContainer ( current : null | Fiber , workInProgress : Fiber ) {
402
406
if ( supportsPersistence ) {
403
- const portalOrRoot : {
404
- containerInfo : Container ,
405
- pendingChildren : ChildSet ,
406
- ...
407
- } = workInProgress . stateNode ;
408
- const childrenUnchanged = hadNoMutationsEffects ( current , workInProgress ) ;
409
- if ( childrenUnchanged ) {
410
- // No changes, just reuse the existing instance.
411
- } else {
407
+ if ( doesRequireClone ( current , workInProgress ) ) {
408
+ const portalOrRoot : {
409
+ containerInfo : Container ,
410
+ pendingChildren : ChildSet ,
411
+ ...
412
+ } = workInProgress . stateNode ;
412
413
const container = portalOrRoot . containerInfo ;
413
414
const newChildSet = createContainerChildSet ( ) ;
414
415
// If children might have changed, we have to add them all to the set.
@@ -449,8 +450,8 @@ function updateHostComponent(
449
450
const oldProps = current . memoizedProps ;
450
451
// If there are no effects associated with this node, then none of our children had any updates.
451
452
// This guarantees that we can reuse all of them.
452
- const childrenUnchanged = hadNoMutationsEffects ( current , workInProgress ) ;
453
- if ( childrenUnchanged && oldProps === newProps ) {
453
+ const requiresClone = doesRequireClone ( current , workInProgress ) ;
454
+ if ( ! requiresClone && oldProps === newProps ) {
454
455
// No changes, just reuse the existing instance.
455
456
// Note that this might release a previous clone.
456
457
workInProgress . stateNode = currentInstance ;
@@ -459,7 +460,7 @@ function updateHostComponent(
459
460
const currentHostContext = getHostContext ( ) ;
460
461
461
462
let newChildSet = null ;
462
- if ( ! childrenUnchanged && passChildrenWhenCloningPersistedNodes ) {
463
+ if ( requiresClone && passChildrenWhenCloningPersistedNodes ) {
463
464
newChildSet = createContainerChildSet ( ) ;
464
465
// If children might have changed, we have to add them all to the set.
465
466
appendAllChildrenToContainer (
@@ -475,7 +476,7 @@ function updateHostComponent(
475
476
type ,
476
477
oldProps ,
477
478
newProps ,
478
- childrenUnchanged ,
479
+ ! requiresClone ,
479
480
newChildSet ,
480
481
) ;
481
482
if ( newInstance === currentInstance ) {
@@ -494,7 +495,7 @@ function updateHostComponent(
494
495
markUpdate ( workInProgress ) ;
495
496
}
496
497
workInProgress . stateNode = newInstance ;
497
- if ( childrenUnchanged ) {
498
+ if ( ! requiresClone ) {
498
499
// If there are no other effects in this tree, we need to flag this node as having one.
499
500
// Even though we're not going to use it for anything.
500
501
// Otherwise parents won't know that there are new children to propagate upwards.
0 commit comments