@samitouri / QOS-React-2 / commits / 9fcaf88d58

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.

Sebastian Markbåge committed Aug 1, 2022 at 23:30 UTC 9fcaf88d58cfd942e2fdd303ae8291dbf4828969
12 files changed +14 -100
packages/react-dom/src/client/ReactDOMComponent.js
+1 -11
@@ -283,7 +283,6 @@ export function trapClickOnNonInteractiveElement(node: HTMLElement) {
283 function setInitialDOMProperties(
284 tag: string,
285 domElement: Element,
286 - rootContainerElement: Element | Document | DocumentFragment,
286 nextProps: Object,
287 isCustomComponentTag: boolean,
288 ): void {
@@ -487,7 +486,6 @@ export function setInitialProperties(
486 domElement: Element,
487 tag: string,
488 rawProps: Object,
490 - rootContainerElement: Element | Document | DocumentFragment,
489 ): void {
490 const isCustomComponentTag = isCustomComponent(tag, rawProps);
491 if (__DEV__) {
@@ -571,13 +569,7 @@ export function setInitialProperties(
569
570 assertValidProps(tag, props);
571
574 - setInitialDOMProperties(
575 - tag,
576 - domElement,
577 - rootContainerElement,
578 - props,
579 - isCustomComponentTag,
580 - );
572 + setInitialDOMProperties(tag, domElement, props, isCustomComponentTag);
573
574 switch (tag) {
575 case 'input':
@@ -613,7 +605,6 @@ export function diffProperties(
605 tag: string,
606 lastRawProps: Object,
607 nextRawProps: Object,
616 - rootContainerElement: Element | Document | DocumentFragment,
608 ): null | Array<mixed> {
609 if (__DEV__) {
610 validatePropertiesInDevelopment(tag, nextRawProps);
@@ -866,7 +857,6 @@ export function diffHydratedProperties(
857 tag: string,
858 rawProps: Object,
859 parentNamespace: string,
869 - rootContainerElement: Element | Document | DocumentFragment,
860 isConcurrentMode: boolean,
861 shouldWarnDev: boolean,
862 ): null | Array<mixed> {
packages/react-dom/src/client/ReactDOMHostConfig.js
+2 -13
@@ -181,7 +181,6 @@ export function getRootHostContext(
181 export function getChildHostContext(
182 parentHostContext: HostContext,
183 type: string,
184 - rootContainerInstance: Container,
184 ): HostContext {
185 if (__DEV__) {
186 const parentHostContextDev = ((parentHostContext: any): HostContextDev);
@@ -289,10 +288,9 @@ export function finalizeInitialChildren(
288 domElement: Instance,
289 type: string,
290 props: Props,
292 - rootContainerInstance: Container,
291 hostContext: HostContext,
292 ): boolean {
295 - setInitialProperties(domElement, type, props, rootContainerInstance);
293 + setInitialProperties(domElement, type, props);
294 switch (type) {
295 case 'button':
296 case 'input':
@@ -311,7 +309,6 @@ export function prepareUpdate(
309 type: string,
310 oldProps: Props,
311 newProps: Props,
314 - rootContainerInstance: Container,
312 hostContext: HostContext,
313 ): null | Array<mixed> {
314 if (__DEV__) {
@@ -329,13 +326,7 @@ export function prepareUpdate(
326 validateDOMNesting(null, string, ownAncestorInfo);
327 }
328 }
332 - return diffProperties(
333 - domElement,
334 - type,
335 - oldProps,
336 - newProps,
337 - rootContainerInstance,
338 - );
329 + return diffProperties(domElement, type, oldProps, newProps);
330 }
331
332 export function shouldSetTextContent(type: string, props: Props): boolean {
@@ -828,7 +819,6 @@ export function hydrateInstance(
819 instance: Instance,
820 type: string,
821 props: Props,
831 - rootContainerInstance: Container,
822 hostContext: HostContext,
823 internalInstanceHandle: Object,
824 shouldWarnDev: boolean,
@@ -855,7 +845,6 @@ export function hydrateInstance(
845 type,
846 props,
847 parentNamespace,
858 - rootContainerInstance,
848 isConcurrentMode,
849 shouldWarnDev,
850 );
packages/react-native-renderer/src/ReactFabricHostConfig.js
-3
@@ -404,7 +404,6 @@ export function finalizeInitialChildren(
404 parentInstance: Instance,
405 type: string,
406 props: Props,
407 - rootContainerInstance: Container,
407 hostContext: HostContext,
408 ): boolean {
409 return false;
@@ -419,7 +418,6 @@ export function getRootHostContext(
418 export function getChildHostContext(
419 parentHostContext: HostContext,
420 type: string,
422 - rootContainerInstance: Container,
421 ): HostContext {
422 const prevIsInAParentText = parentHostContext.isInAParentText;
423 const isInAParentText =
@@ -453,7 +451,6 @@ export function prepareUpdate(
451 type: string,
452 oldProps: Props,
453 newProps: Props,
456 - rootContainerInstance: Container,
454 hostContext: HostContext,
455 ): null | Object {
456 const viewConfig = instance.canonical.viewConfig;
packages/react-native-renderer/src/ReactNativeHostConfig.js
-3
@@ -166,7 +166,6 @@ export function finalizeInitialChildren(
166 parentInstance: Instance,
167 type: string,
168 props: Props,
169 - rootContainerInstance: Container,
169 hostContext: HostContext,
170 ): boolean {
171 // Don't send a no-op message over the bridge.
@@ -199,7 +198,6 @@ export function getRootHostContext(
198 export function getChildHostContext(
199 parentHostContext: HostContext,
200 type: string,
202 - rootContainerInstance: Container,
201 ): HostContext {
202 const prevIsInAParentText = parentHostContext.isInAParentText;
203 const isInAParentText =
@@ -230,7 +228,6 @@ export function prepareUpdate(
228 type: string,
229 oldProps: Props,
230 newProps: Props,
233 - rootContainerInstance: Container,
231 hostContext: HostContext,
232 ): null | Object {
233 return UPDATE_SIGNAL;
packages/react-noop-renderer/src/createReactNoop.js
+1 -5
@@ -276,11 +276,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
276 return NO_CONTEXT;
277 },
278
279 - getChildHostContext(
280 - parentHostContext: HostContext,
281 - type: string,
282 - rootcontainerInstance: Container,
283 - ) {
279 + getChildHostContext(parentHostContext: HostContext, type: string) {
280 if (type === 'offscreen') {
281 return parentHostContext;
282 }
packages/react-reconciler/src/ReactFiberCompleteWork.new.js
+4 -26
@@ -255,7 +255,6 @@ if (supportsMutation) {
255 workInProgress: Fiber,
256 type: Type,
257 newProps: Props,
258 - rootContainerInstance: Container,
258 ) {
259 // If we have an alternate, that means this is an update and we need to
260 // schedule a side-effect to do the updates.
@@ -280,7 +279,6 @@ if (supportsMutation) {
279 type,
280 oldProps,
281 newProps,
283 - rootContainerInstance,
282 currentHostContext,
283 );
284 // TODO: Type this specific to this type of component.
@@ -458,7 +456,6 @@ if (supportsMutation) {
456 workInProgress: Fiber,
457 type: Type,
458 newProps: Props,
461 - rootContainerInstance: Container,
459 ) {
460 const currentInstance = current.stateNode;
461 const oldProps = current.memoizedProps;
@@ -480,7 +477,6 @@ if (supportsMutation) {
477 type,
478 oldProps,
479 newProps,
483 - rootContainerInstance,
480 currentHostContext,
481 );
482 }
@@ -501,13 +497,7 @@ if (supportsMutation) {
497 recyclableInstance,
498 );
499 if (
504 - finalizeInitialChildren(
505 - newInstance,
506 - type,
507 - newProps,
508 - rootContainerInstance,
509 - currentHostContext,
510 - )
500 + finalizeInitialChildren(newInstance, type, newProps, currentHostContext)
501 ) {
502 markUpdate(workInProgress);
503 }
@@ -555,7 +545,6 @@ if (supportsMutation) {
545 workInProgress: Fiber,
546 type: Type,
547 newProps: Props,
558 - rootContainerInstance: Container,
548 ) {
549 // Noop
550 };
@@ -964,16 +953,9 @@ function completeWork(
953 }
954 case HostComponent: {
955 popHostContext(workInProgress);
967 - const rootContainerInstance = getRootHostContainer();
956 const type = workInProgress.type;
957 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);
959
960 if (current.ref !== workInProgress.ref) {
961 markRef(workInProgress);
@@ -1002,17 +984,14 @@ function completeWork(
984 // TODO: Move this and createInstance step into the beginPhase
985 // to consolidate.
986 if (
1005 - prepareToHydrateHostInstance(
1006 - workInProgress,
1007 - rootContainerInstance,
1008 - currentHostContext,
1009 - )
987 + prepareToHydrateHostInstance(workInProgress, currentHostContext)
988 ) {
989 // If changes to the hydrated node need to be applied at the
990 // commit-phase we mark this as such.
991 markUpdate(workInProgress);
992 }
993 } else {
994 + const rootContainerInstance = getRootHostContainer();
995 const instance = createInstance(
996 type,
997 newProps,
@@ -1033,7 +1012,6 @@ function completeWork(
1012 instance,
1013 type,
1014 newProps,
1036 - rootContainerInstance,
1015 currentHostContext,
1016 )
1017 ) {
packages/react-reconciler/src/ReactFiberCompleteWork.old.js
+4 -26
@@ -255,7 +255,6 @@ if (supportsMutation) {
255 workInProgress: Fiber,
256 type: Type,
257 newProps: Props,
258 - rootContainerInstance: Container,
258 ) {
259 // If we have an alternate, that means this is an update and we need to
260 // schedule a side-effect to do the updates.
@@ -280,7 +279,6 @@ if (supportsMutation) {
279 type,
280 oldProps,
281 newProps,
283 - rootContainerInstance,
282 currentHostContext,
283 );
284 // TODO: Type this specific to this type of component.
@@ -458,7 +456,6 @@ if (supportsMutation) {
456 workInProgress: Fiber,
457 type: Type,
458 newProps: Props,
461 - rootContainerInstance: Container,
459 ) {
460 const currentInstance = current.stateNode;
461 const oldProps = current.memoizedProps;
@@ -480,7 +477,6 @@ if (supportsMutation) {
477 type,
478 oldProps,
479 newProps,
483 - rootContainerInstance,
480 currentHostContext,
481 );
482 }
@@ -501,13 +497,7 @@ if (supportsMutation) {
497 recyclableInstance,
498 );
499 if (
504 - finalizeInitialChildren(
505 - newInstance,
506 - type,
507 - newProps,
508 - rootContainerInstance,
509 - currentHostContext,
510 - )
500 + finalizeInitialChildren(newInstance, type, newProps, currentHostContext)
501 ) {
502 markUpdate(workInProgress);
503 }
@@ -555,7 +545,6 @@ if (supportsMutation) {
545 workInProgress: Fiber,
546 type: Type,
547 newProps: Props,
558 - rootContainerInstance: Container,
548 ) {
549 // Noop
550 };
@@ -964,16 +953,9 @@ function completeWork(
953 }
954 case HostComponent: {
955 popHostContext(workInProgress);
967 - const rootContainerInstance = getRootHostContainer();
956 const type = workInProgress.type;
957 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);
959
960 if (current.ref !== workInProgress.ref) {
961 markRef(workInProgress);
@@ -1002,17 +984,14 @@ function completeWork(
984 // TODO: Move this and createInstance step into the beginPhase
985 // to consolidate.
986 if (
1005 - prepareToHydrateHostInstance(
1006 - workInProgress,
1007 - rootContainerInstance,
1008 - currentHostContext,
1009 - )
987 + prepareToHydrateHostInstance(workInProgress, currentHostContext)
988 ) {
989 // If changes to the hydrated node need to be applied at the
990 // commit-phase we mark this as such.
991 markUpdate(workInProgress);
992 }
993 } else {
994 + const rootContainerInstance = getRootHostContainer();
995 const instance = createInstance(
996 type,
997 newProps,
@@ -1033,7 +1012,6 @@ function completeWork(
1012 instance,
1013 type,
1014 newProps,
1036 - rootContainerInstance,
1015 currentHostContext,
1016 )
1017 ) {
packages/react-reconciler/src/ReactFiberHostContext.new.js
+1 -4
@@ -75,11 +75,8 @@ function getHostContext(): HostContext {
75 }
76
77 function pushHostContext(fiber: Fiber): void {
78 - const rootInstance: Container = requiredContext(
79 - rootInstanceStackCursor.current,
80 - );
78 const context: HostContext = requiredContext(contextStackCursor.current);
82 - const nextContext = getChildHostContext(context, fiber.type, rootInstance);
79 + const nextContext = getChildHostContext(context, fiber.type);
80
81 // Don't push this Fiber's context unless it's unique.
82 if (context === nextContext) {
packages/react-reconciler/src/ReactFiberHostContext.old.js
+1 -4
@@ -75,11 +75,8 @@ function getHostContext(): HostContext {
75 }
76
77 function pushHostContext(fiber: Fiber): void {
78 - const rootInstance: Container = requiredContext(
79 - rootInstanceStackCursor.current,
80 - );
78 const context: HostContext = requiredContext(contextStackCursor.current);
82 - const nextContext = getChildHostContext(context, fiber.type, rootInstance);
79 + const nextContext = getChildHostContext(context, fiber.type);
80
81 // Don't push this Fiber's context unless it's unique.
82 if (context === nextContext) {
packages/react-reconciler/src/ReactFiberHydrationContext.new.js
-2
@@ -444,7 +444,6 @@ function tryToClaimNextHydratableInstance(fiber: Fiber): void {
444
445 function prepareToHydrateHostInstance(
446 fiber: Fiber,
447 - rootContainerInstance: Container,
447 hostContext: HostContext,
448 ): boolean {
449 if (!supportsHydration) {
@@ -460,7 +459,6 @@ function prepareToHydrateHostInstance(
459 instance,
460 fiber.type,
461 fiber.memoizedProps,
463 - rootContainerInstance,
462 hostContext,
463 fiber,
464 shouldWarnIfMismatchDev,
packages/react-reconciler/src/ReactFiberHydrationContext.old.js
-2
@@ -444,7 +444,6 @@ function tryToClaimNextHydratableInstance(fiber: Fiber): void {
444
445 function prepareToHydrateHostInstance(
446 fiber: Fiber,
447 - rootContainerInstance: Container,
447 hostContext: HostContext,
448 ): boolean {
449 if (!supportsHydration) {
@@ -460,7 +459,6 @@ function prepareToHydrateHostInstance(
459 instance,
460 fiber.type,
461 fiber.memoizedProps,
463 - rootContainerInstance,
462 hostContext,
463 fiber,
464 shouldWarnIfMismatchDev,
packages/react-test-renderer/src/ReactTestHostConfig.js
-1
@@ -128,7 +128,6 @@ export function getRootHostContext(
128 export function getChildHostContext(
129 parentHostContext: HostContext,
130 type: string,
131 - rootContainerInstance: Container,
131 ): HostContext {
132 return NO_CONTEXT;
133 }