Skip to content

Commit 9fcaf88

Browse files
authored
Remove rootContainerInstance from unnecessary places (#25024)
We only really use this for the create APIs since the DOM requires it. We could probably use the Host Context for this instead since they're updated at the same time and the namespace is related to this concept.
1 parent 3f3b46c commit 9fcaf88

12 files changed

+14
-100
lines changed

packages/react-dom/src/client/ReactDOMComponent.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ export function trapClickOnNonInteractiveElement(node: HTMLElement) {
283283
function setInitialDOMProperties(
284284
tag: string,
285285
domElement: Element,
286-
rootContainerElement: Element | Document | DocumentFragment,
287286
nextProps: Object,
288287
isCustomComponentTag: boolean,
289288
): void {
@@ -487,7 +486,6 @@ export function setInitialProperties(
487486
domElement: Element,
488487
tag: string,
489488
rawProps: Object,
490-
rootContainerElement: Element | Document | DocumentFragment,
491489
): void {
492490
const isCustomComponentTag = isCustomComponent(tag, rawProps);
493491
if (__DEV__) {
@@ -571,13 +569,7 @@ export function setInitialProperties(
571569

572570
assertValidProps(tag, props);
573571

574-
setInitialDOMProperties(
575-
tag,
576-
domElement,
577-
rootContainerElement,
578-
props,
579-
isCustomComponentTag,
580-
);
572+
setInitialDOMProperties(tag, domElement, props, isCustomComponentTag);
581573

582574
switch (tag) {
583575
case 'input':
@@ -613,7 +605,6 @@ export function diffProperties(
613605
tag: string,
614606
lastRawProps: Object,
615607
nextRawProps: Object,
616-
rootContainerElement: Element | Document | DocumentFragment,
617608
): null | Array<mixed> {
618609
if (__DEV__) {
619610
validatePropertiesInDevelopment(tag, nextRawProps);
@@ -866,7 +857,6 @@ export function diffHydratedProperties(
866857
tag: string,
867858
rawProps: Object,
868859
parentNamespace: string,
869-
rootContainerElement: Element | Document | DocumentFragment,
870860
isConcurrentMode: boolean,
871861
shouldWarnDev: boolean,
872862
): null | Array<mixed> {

packages/react-dom/src/client/ReactDOMHostConfig.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ export function getRootHostContext(
181181
export function getChildHostContext(
182182
parentHostContext: HostContext,
183183
type: string,
184-
rootContainerInstance: Container,
185184
): HostContext {
186185
if (__DEV__) {
187186
const parentHostContextDev = ((parentHostContext: any): HostContextDev);
@@ -289,10 +288,9 @@ export function finalizeInitialChildren(
289288
domElement: Instance,
290289
type: string,
291290
props: Props,
292-
rootContainerInstance: Container,
293291
hostContext: HostContext,
294292
): boolean {
295-
setInitialProperties(domElement, type, props, rootContainerInstance);
293+
setInitialProperties(domElement, type, props);
296294
switch (type) {
297295
case 'button':
298296
case 'input':
@@ -311,7 +309,6 @@ export function prepareUpdate(
311309
type: string,
312310
oldProps: Props,
313311
newProps: Props,
314-
rootContainerInstance: Container,
315312
hostContext: HostContext,
316313
): null | Array<mixed> {
317314
if (__DEV__) {
@@ -329,13 +326,7 @@ export function prepareUpdate(
329326
validateDOMNesting(null, string, ownAncestorInfo);
330327
}
331328
}
332-
return diffProperties(
333-
domElement,
334-
type,
335-
oldProps,
336-
newProps,
337-
rootContainerInstance,
338-
);
329+
return diffProperties(domElement, type, oldProps, newProps);
339330
}
340331

341332
export function shouldSetTextContent(type: string, props: Props): boolean {
@@ -828,7 +819,6 @@ export function hydrateInstance(
828819
instance: Instance,
829820
type: string,
830821
props: Props,
831-
rootContainerInstance: Container,
832822
hostContext: HostContext,
833823
internalInstanceHandle: Object,
834824
shouldWarnDev: boolean,
@@ -855,7 +845,6 @@ export function hydrateInstance(
855845
type,
856846
props,
857847
parentNamespace,
858-
rootContainerInstance,
859848
isConcurrentMode,
860849
shouldWarnDev,
861850
);

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

-3
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ export function finalizeInitialChildren(
404404
parentInstance: Instance,
405405
type: string,
406406
props: Props,
407-
rootContainerInstance: Container,
408407
hostContext: HostContext,
409408
): boolean {
410409
return false;
@@ -419,7 +418,6 @@ export function getRootHostContext(
419418
export function getChildHostContext(
420419
parentHostContext: HostContext,
421420
type: string,
422-
rootContainerInstance: Container,
423421
): HostContext {
424422
const prevIsInAParentText = parentHostContext.isInAParentText;
425423
const isInAParentText =
@@ -453,7 +451,6 @@ export function prepareUpdate(
453451
type: string,
454452
oldProps: Props,
455453
newProps: Props,
456-
rootContainerInstance: Container,
457454
hostContext: HostContext,
458455
): null | Object {
459456
const viewConfig = instance.canonical.viewConfig;

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

-3
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ export function finalizeInitialChildren(
166166
parentInstance: Instance,
167167
type: string,
168168
props: Props,
169-
rootContainerInstance: Container,
170169
hostContext: HostContext,
171170
): boolean {
172171
// Don't send a no-op message over the bridge.
@@ -199,7 +198,6 @@ export function getRootHostContext(
199198
export function getChildHostContext(
200199
parentHostContext: HostContext,
201200
type: string,
202-
rootContainerInstance: Container,
203201
): HostContext {
204202
const prevIsInAParentText = parentHostContext.isInAParentText;
205203
const isInAParentText =
@@ -230,7 +228,6 @@ export function prepareUpdate(
230228
type: string,
231229
oldProps: Props,
232230
newProps: Props,
233-
rootContainerInstance: Container,
234231
hostContext: HostContext,
235232
): null | Object {
236233
return UPDATE_SIGNAL;

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
276276
return NO_CONTEXT;
277277
},
278278

279-
getChildHostContext(
280-
parentHostContext: HostContext,
281-
type: string,
282-
rootcontainerInstance: Container,
283-
) {
279+
getChildHostContext(parentHostContext: HostContext, type: string) {
284280
if (type === 'offscreen') {
285281
return parentHostContext;
286282
}

packages/react-reconciler/src/ReactFiberCompleteWork.new.js

+4-26
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ if (supportsMutation) {
255255
workInProgress: Fiber,
256256
type: Type,
257257
newProps: Props,
258-
rootContainerInstance: Container,
259258
) {
260259
// If we have an alternate, that means this is an update and we need to
261260
// schedule a side-effect to do the updates.
@@ -280,7 +279,6 @@ if (supportsMutation) {
280279
type,
281280
oldProps,
282281
newProps,
283-
rootContainerInstance,
284282
currentHostContext,
285283
);
286284
// TODO: Type this specific to this type of component.
@@ -458,7 +456,6 @@ if (supportsMutation) {
458456
workInProgress: Fiber,
459457
type: Type,
460458
newProps: Props,
461-
rootContainerInstance: Container,
462459
) {
463460
const currentInstance = current.stateNode;
464461
const oldProps = current.memoizedProps;
@@ -480,7 +477,6 @@ if (supportsMutation) {
480477
type,
481478
oldProps,
482479
newProps,
483-
rootContainerInstance,
484480
currentHostContext,
485481
);
486482
}
@@ -501,13 +497,7 @@ if (supportsMutation) {
501497
recyclableInstance,
502498
);
503499
if (
504-
finalizeInitialChildren(
505-
newInstance,
506-
type,
507-
newProps,
508-
rootContainerInstance,
509-
currentHostContext,
510-
)
500+
finalizeInitialChildren(newInstance, type, newProps, currentHostContext)
511501
) {
512502
markUpdate(workInProgress);
513503
}
@@ -555,7 +545,6 @@ if (supportsMutation) {
555545
workInProgress: Fiber,
556546
type: Type,
557547
newProps: Props,
558-
rootContainerInstance: Container,
559548
) {
560549
// Noop
561550
};
@@ -964,16 +953,9 @@ function completeWork(
964953
}
965954
case HostComponent: {
966955
popHostContext(workInProgress);
967-
const rootContainerInstance = getRootHostContainer();
968956
const type = workInProgress.type;
969957
if (current !== null && workInProgress.stateNode != null) {
970-
updateHostComponent(
971-
current,
972-
workInProgress,
973-
type,
974-
newProps,
975-
rootContainerInstance,
976-
);
958+
updateHostComponent(current, workInProgress, type, newProps);
977959

978960
if (current.ref !== workInProgress.ref) {
979961
markRef(workInProgress);
@@ -1002,17 +984,14 @@ function completeWork(
1002984
// TODO: Move this and createInstance step into the beginPhase
1003985
// to consolidate.
1004986
if (
1005-
prepareToHydrateHostInstance(
1006-
workInProgress,
1007-
rootContainerInstance,
1008-
currentHostContext,
1009-
)
987+
prepareToHydrateHostInstance(workInProgress, currentHostContext)
1010988
) {
1011989
// If changes to the hydrated node need to be applied at the
1012990
// commit-phase we mark this as such.
1013991
markUpdate(workInProgress);
1014992
}
1015993
} else {
994+
const rootContainerInstance = getRootHostContainer();
1016995
const instance = createInstance(
1017996
type,
1018997
newProps,
@@ -1033,7 +1012,6 @@ function completeWork(
10331012
instance,
10341013
type,
10351014
newProps,
1036-
rootContainerInstance,
10371015
currentHostContext,
10381016
)
10391017
) {

packages/react-reconciler/src/ReactFiberCompleteWork.old.js

+4-26
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ if (supportsMutation) {
255255
workInProgress: Fiber,
256256
type: Type,
257257
newProps: Props,
258-
rootContainerInstance: Container,
259258
) {
260259
// If we have an alternate, that means this is an update and we need to
261260
// schedule a side-effect to do the updates.
@@ -280,7 +279,6 @@ if (supportsMutation) {
280279
type,
281280
oldProps,
282281
newProps,
283-
rootContainerInstance,
284282
currentHostContext,
285283
);
286284
// TODO: Type this specific to this type of component.
@@ -458,7 +456,6 @@ if (supportsMutation) {
458456
workInProgress: Fiber,
459457
type: Type,
460458
newProps: Props,
461-
rootContainerInstance: Container,
462459
) {
463460
const currentInstance = current.stateNode;
464461
const oldProps = current.memoizedProps;
@@ -480,7 +477,6 @@ if (supportsMutation) {
480477
type,
481478
oldProps,
482479
newProps,
483-
rootContainerInstance,
484480
currentHostContext,
485481
);
486482
}
@@ -501,13 +497,7 @@ if (supportsMutation) {
501497
recyclableInstance,
502498
);
503499
if (
504-
finalizeInitialChildren(
505-
newInstance,
506-
type,
507-
newProps,
508-
rootContainerInstance,
509-
currentHostContext,
510-
)
500+
finalizeInitialChildren(newInstance, type, newProps, currentHostContext)
511501
) {
512502
markUpdate(workInProgress);
513503
}
@@ -555,7 +545,6 @@ if (supportsMutation) {
555545
workInProgress: Fiber,
556546
type: Type,
557547
newProps: Props,
558-
rootContainerInstance: Container,
559548
) {
560549
// Noop
561550
};
@@ -964,16 +953,9 @@ function completeWork(
964953
}
965954
case HostComponent: {
966955
popHostContext(workInProgress);
967-
const rootContainerInstance = getRootHostContainer();
968956
const type = workInProgress.type;
969957
if (current !== null && workInProgress.stateNode != null) {
970-
updateHostComponent(
971-
current,
972-
workInProgress,
973-
type,
974-
newProps,
975-
rootContainerInstance,
976-
);
958+
updateHostComponent(current, workInProgress, type, newProps);
977959

978960
if (current.ref !== workInProgress.ref) {
979961
markRef(workInProgress);
@@ -1002,17 +984,14 @@ function completeWork(
1002984
// TODO: Move this and createInstance step into the beginPhase
1003985
// to consolidate.
1004986
if (
1005-
prepareToHydrateHostInstance(
1006-
workInProgress,
1007-
rootContainerInstance,
1008-
currentHostContext,
1009-
)
987+
prepareToHydrateHostInstance(workInProgress, currentHostContext)
1010988
) {
1011989
// If changes to the hydrated node need to be applied at the
1012990
// commit-phase we mark this as such.
1013991
markUpdate(workInProgress);
1014992
}
1015993
} else {
994+
const rootContainerInstance = getRootHostContainer();
1016995
const instance = createInstance(
1017996
type,
1018997
newProps,
@@ -1033,7 +1012,6 @@ function completeWork(
10331012
instance,
10341013
type,
10351014
newProps,
1036-
rootContainerInstance,
10371015
currentHostContext,
10381016
)
10391017
) {

packages/react-reconciler/src/ReactFiberHostContext.new.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,8 @@ function getHostContext(): HostContext {
7575
}
7676

7777
function pushHostContext(fiber: Fiber): void {
78-
const rootInstance: Container = requiredContext(
79-
rootInstanceStackCursor.current,
80-
);
8178
const context: HostContext = requiredContext(contextStackCursor.current);
82-
const nextContext = getChildHostContext(context, fiber.type, rootInstance);
79+
const nextContext = getChildHostContext(context, fiber.type);
8380

8481
// Don't push this Fiber's context unless it's unique.
8582
if (context === nextContext) {

packages/react-reconciler/src/ReactFiberHostContext.old.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,8 @@ function getHostContext(): HostContext {
7575
}
7676

7777
function pushHostContext(fiber: Fiber): void {
78-
const rootInstance: Container = requiredContext(
79-
rootInstanceStackCursor.current,
80-
);
8178
const context: HostContext = requiredContext(contextStackCursor.current);
82-
const nextContext = getChildHostContext(context, fiber.type, rootInstance);
79+
const nextContext = getChildHostContext(context, fiber.type);
8380

8481
// Don't push this Fiber's context unless it's unique.
8582
if (context === nextContext) {

0 commit comments

Comments
 (0)