@@ -232,8 +232,16 @@ export function commitShowHideHostTextInstance(node: Fiber, isHidden: boolean) {
232
232
233
233
export function commitNewChildToFragmentInstances (
234
234
fiber : Fiber ,
235
- parentFragmentInstances : Array < FragmentInstanceType > ,
235
+ parentFragmentInstances : null | Array < FragmentInstanceType > ,
236
236
) : void {
237
+ if (
238
+ fiber . tag !== HostComponent ||
239
+ // Only run fragment insertion effects for initial insertions
240
+ fiber . alternate !== null ||
241
+ parentFragmentInstances === null
242
+ ) {
243
+ return ;
244
+ }
237
245
for ( let i = 0 ; i < parentFragmentInstances . length ; i ++ ) {
238
246
const fragmentInstance = parentFragmentInstances [ i ] ;
239
247
commitNewChildToFragmentInstance ( fiber . stateNode , fragmentInstance ) ;
@@ -361,14 +369,7 @@ function insertOrAppendPlacementNodeIntoContainer(
361
369
} else {
362
370
appendChildToContainer ( parent , stateNode ) ;
363
371
}
364
- // TODO: Enable HostText for RN
365
- if (
366
- enableFragmentRefs &&
367
- tag === HostComponent &&
368
- // Only run fragment insertion effects for initial insertions
369
- node . alternate === null &&
370
- parentFragmentInstances !== null
371
- ) {
372
+ if ( enableFragmentRefs ) {
372
373
commitNewChildToFragmentInstances ( node , parentFragmentInstances ) ;
373
374
}
374
375
trackHostMutation ( ) ;
@@ -426,14 +427,7 @@ function insertOrAppendPlacementNode(
426
427
} else {
427
428
appendChild ( parent , stateNode ) ;
428
429
}
429
- // TODO: Enable HostText for RN
430
- if (
431
- enableFragmentRefs &&
432
- tag === HostComponent &&
433
- // Only run fragment insertion effects for initial insertions
434
- node . alternate === null &&
435
- parentFragmentInstances !== null
436
- ) {
430
+ if ( enableFragmentRefs ) {
437
431
commitNewChildToFragmentInstances ( node , parentFragmentInstances ) ;
438
432
}
439
433
trackHostMutation ( ) ;
@@ -471,7 +465,7 @@ function insertOrAppendPlacementNode(
471
465
}
472
466
473
467
function commitPlacement ( finishedWork : Fiber ) : void {
474
- if ( ! supportsMutation ) {
468
+ if ( ! supportsMutation && ! enableFragmentRefs ) {
475
469
return ;
476
470
}
477
471
@@ -500,6 +494,13 @@ function commitPlacement(finishedWork: Fiber): void {
500
494
'in React. Please file an issue.' ,
501
495
) ;
502
496
}
497
+ if ( ! supportsMutation && enableFragmentRefs ) {
498
+ appendImmutableNodeToFragmentInstances (
499
+ finishedWork ,
500
+ parentFragmentInstances ,
501
+ ) ;
502
+ return ;
503
+ }
503
504
504
505
switch ( hostParentFiber . tag ) {
505
506
case HostSingleton : {
@@ -558,6 +559,35 @@ function commitPlacement(finishedWork: Fiber): void {
558
559
}
559
560
}
560
561
562
+ function appendImmutableNodeToFragmentInstances (
563
+ finishedWork : Fiber ,
564
+ parentFragmentInstances : null | Array < FragmentInstanceType > ,
565
+ ) : void {
566
+ if ( ! enableFragmentRefs ) {
567
+ return ;
568
+ }
569
+ const isHost = finishedWork . tag === HostComponent ;
570
+ if ( isHost ) {
571
+ commitNewChildToFragmentInstances ( finishedWork , parentFragmentInstances ) ;
572
+ return ;
573
+ } else if ( finishedWork . tag === HostPortal ) {
574
+ // If the insertion itself is a portal, then we don't want to traverse
575
+ // down its children. Instead, we'll get insertions from each child in
576
+ // the portal directly.
577
+ return ;
578
+ }
579
+
580
+ const child = finishedWork . child ;
581
+ if ( child !== null ) {
582
+ appendImmutableNodeToFragmentInstances ( child , parentFragmentInstances ) ;
583
+ let sibling = child . sibling ;
584
+ while ( sibling !== null ) {
585
+ appendImmutableNodeToFragmentInstances ( sibling , parentFragmentInstances ) ;
586
+ sibling = sibling . sibling ;
587
+ }
588
+ }
589
+ }
590
+
561
591
export function commitHostPlacement ( finishedWork : Fiber ) {
562
592
try {
563
593
if ( __DEV__ ) {
0 commit comments