Skip to content

Commit e996d90

Browse files
committed
[Fabric] Track child set as array instead of native datastructure
1 parent c9c467e commit e996d90

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

packages/react-native-renderer/src/ReactFiberConfigFabric.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ const {
4747
unstable_getCurrentEventPriority: fabricGetCurrentEventPriority,
4848
} = nativeFabricUIManager;
4949

50-
import {useMicrotasksForSchedulingInFabric} from 'shared/ReactFeatureFlags';
50+
import {
51+
useMicrotasksForSchedulingInFabric,
52+
passChildrenWhenCloningPersistedNodes,
53+
} from 'shared/ReactFeatureFlags';
5154

5255
const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;
5356

@@ -87,7 +90,7 @@ export type TextInstance = {
8790
export type HydratableInstance = Instance | TextInstance;
8891
export type PublicInstance = ReactNativePublicInstance;
8992
export type Container = number;
90-
export type ChildSet = Object;
93+
export type ChildSet = Object | Array<Node>;
9194
export type HostContext = $ReadOnly<{
9295
isInAParentText: boolean,
9396
}>;
@@ -405,15 +408,23 @@ export function cloneHiddenTextInstance(
405408
throw new Error('Not yet implemented.');
406409
}
407410

408-
export function createContainerChildSet(container: Container): ChildSet {
409-
return createChildNodeSet(container);
411+
export function createContainerChildSet(): ChildSet {
412+
if (passChildrenWhenCloningPersistedNodes) {
413+
return [];
414+
} else {
415+
return createChildNodeSet();
416+
}
410417
}
411418

412419
export function appendChildToContainerChildSet(
413420
childSet: ChildSet,
414421
child: Instance | TextInstance,
415422
): void {
416-
appendChildNodeToSet(childSet, child.node);
423+
if (passChildrenWhenCloningPersistedNodes) {
424+
childSet.push(child.node);
425+
} else {
426+
appendChildNodeToSet(childSet, child.node);
427+
}
417428
}
418429

419430
export function finalizeContainerChildren(
@@ -426,7 +437,9 @@ export function finalizeContainerChildren(
426437
export function replaceContainerChildren(
427438
container: Container,
428439
newChildren: ChildSet,
429-
): void {}
440+
): void {
441+
// Noop - children will be replaced in finalizeContainerChildren
442+
}
430443

431444
export function getInstanceFromNode(node: any): empty {
432445
throw new Error('Not yet implemented.');

packages/react-noop-renderer/src/createReactNoop.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
704704
cloneInstance,
705705
clearContainer,
706706

707-
createContainerChildSet(
708-
container: Container,
709-
): Array<Instance | TextInstance> {
707+
createContainerChildSet(): Array<Instance | TextInstance> {
710708
return [];
711709
},
712710

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,7 @@ function emptyPortalContainer(current: Fiber) {
17241724
...
17251725
} = current.stateNode;
17261726
const {containerInfo} = portal;
1727-
const emptyChildSet = createContainerChildSet(containerInfo);
1727+
const emptyChildSet = createContainerChildSet();
17281728
replaceContainerChildren(containerInfo, emptyChildSet);
17291729
}
17301730

packages/react-reconciler/src/ReactFiberCompleteWork.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ function appendAllChildrenToContainer(
390390
}
391391
}
392392
}
393+
393394
function updateHostContainer(current: null | Fiber, workInProgress: Fiber) {
394395
if (supportsPersistence) {
395396
const portalOrRoot: {
@@ -402,16 +403,22 @@ function updateHostContainer(current: null | Fiber, workInProgress: Fiber) {
402403
// No changes, just reuse the existing instance.
403404
} else {
404405
const container = portalOrRoot.containerInfo;
405-
const newChildSet = createContainerChildSet(container);
406+
const newChildSet = createContainerChildSet();
406407
// If children might have changed, we have to add them all to the set.
407-
appendAllChildrenToContainer(newChildSet, workInProgress, false, false);
408+
appendAllChildrenToContainer(
409+
newChildSet,
410+
workInProgress,
411+
/* needsVisibilityToggle */ false,
412+
/* isHidden */ false,
413+
);
408414
portalOrRoot.pendingChildren = newChildSet;
409415
// Schedule an update on the container to swap out the container.
410416
markUpdate(workInProgress);
411417
finalizeContainerChildren(container, newChildSet);
412418
}
413419
}
414420
}
421+
415422
function updateHostComponent(
416423
current: Fiber,
417424
workInProgress: Fiber,
@@ -460,6 +467,9 @@ function updateHostComponent(
460467
return;
461468
}
462469

470+
// Certain renderers require commit-time effects for initial mount.
471+
// (eg DOM renderer supports auto-focus for certain elements).
472+
// Make sure such renderers get scheduled for later work.
463473
if (
464474
finalizeInitialChildren(newInstance, type, newProps, currentHostContext)
465475
) {
@@ -473,7 +483,12 @@ function updateHostComponent(
473483
markUpdate(workInProgress);
474484
} else {
475485
// If children might have changed, we have to add them all to the set.
476-
appendAllChildren(newInstance, workInProgress, false, false);
486+
appendAllChildren(
487+
newInstance,
488+
workInProgress,
489+
/* needsVisibilityToggle */ false,
490+
/* isHidden */ false,
491+
);
477492
}
478493
}
479494
}

scripts/flow/react-native-host-hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ declare var nativeFabricUIManager: {
181181
cloneNodeWithNewChildrenAndProps: (node: Object, newProps: ?Object) => Object,
182182
appendChild: (node: Object, childNode: Object) => void,
183183

184-
createChildSet: (rootTag: number) => Object,
184+
createChildSet: () => Object,
185185
appendChildToSet: (childSet: Object, childNode: Object) => void,
186186
completeRoot: (rootTag: number, childSet: Object) => void,
187187
registerEventHandler: (

0 commit comments

Comments
 (0)