255
256
export function commitNewChildToFragmentInstances(
257
fiber: Fiber,
258
- parentFragmentInstances: Array<FragmentInstanceType>,
258
+ parentFragmentInstances: null | Array<FragmentInstanceType>,
259
): void {
260
+ if (
261
+ fiber.tag !== HostComponent ||
262
+ // Only run fragment insertion effects for initial insertions
263
+ fiber.alternate !== null ||
264
+ parentFragmentInstances === null
265
+ ) {
266
+ return;
267
+ }
268
for (let i = 0; i < parentFragmentInstances.length; i++) {
269
const fragmentInstance = parentFragmentInstances[i];
270
commitNewChildToFragmentInstance(fiber.stateNode, fragmentInstance);
392
} else {
393
appendChildToContainer(parent, stateNode);
394
}
387
- // TODO: Enable HostText for RN
388
- if (
389
- enableFragmentRefs &&
390
- tag === HostComponent &&
391
- // Only run fragment insertion effects for initial insertions
392
- node.alternate === null &&
393
- parentFragmentInstances !== null
394
- ) {
395
+ if (enableFragmentRefs) {
396
commitNewChildToFragmentInstances(node, parentFragmentInstances);
397
}
398
trackHostMutation();
450
} else {
451
appendChild(parent, stateNode);
452
}
452
- // TODO: Enable HostText for RN
453
- if (
454
- enableFragmentRefs &&
455
- tag === HostComponent &&
456
- // Only run fragment insertion effects for initial insertions
457
- node.alternate === null &&
458
- parentFragmentInstances !== null
459
- ) {
453
+ if (enableFragmentRefs) {
454
commitNewChildToFragmentInstances(node, parentFragmentInstances);
455
}
456
trackHostMutation();
488
}
489
490
function commitPlacement(finishedWork: Fiber): void {
497
- if (!supportsMutation) {
498
- return;
499
- }
500
-
491
// Recursively insert all host nodes into the parent.
492
let hostParentFiber;
493
let parentFragmentInstances = null;
507
}
508
parentFiber = parentFiber.return;
509
}
510
+
511
+ if (!supportsMutation) {
512
+ if (enableFragmentRefs) {
513
+ commitImmutablePlacementNodeToFragmentInstances(
514
+ finishedWork,
515
+ parentFragmentInstances,
516
+ );
517
+ }
518
+ return;
519
+ }
520
+
521
if (hostParentFiber == null) {
522
throw new Error(
523
'Expected to find a host parent. This error is likely caused by a bug ' +
582
}
583
}
584
585
+function commitImmutablePlacementNodeToFragmentInstances(
586
+ finishedWork: Fiber,
587
+ parentFragmentInstances: null | Array<FragmentInstanceType>,
588
+): void {
589
+ if (!enableFragmentRefs) {
590
+ return;
591
+ }
592
+ const isHost = finishedWork.tag === HostComponent;
593
+ if (isHost) {
594
+ commitNewChildToFragmentInstances(finishedWork, parentFragmentInstances);
595
+ return;
596
+ } else if (finishedWork.tag === HostPortal) {
597
+ // If the insertion itself is a portal, then we don't want to traverse
598
+ // down its children. Instead, we'll get insertions from each child in
599
+ // the portal directly.
600
+ return;
601
+ }
602
+
603
+ const child = finishedWork.child;
604
+ if (child !== null) {
605
+ commitImmutablePlacementNodeToFragmentInstances(
606
+ child,
607
+ parentFragmentInstances,
608
+ );
609
+ let sibling = child.sibling;
610
+ while (sibling !== null) {
611
+ commitImmutablePlacementNodeToFragmentInstances(
612
+ sibling,
613
+ parentFragmentInstances,
614
+ );
615
+ sibling = sibling.sibling;
616
+ }
617
+ }
618
+}
619
+
620
export function commitHostPlacement(finishedWork: Fiber) {
621
try {
622
if (__DEV__) {