From 9fcaf88d58cfd942e2fdd303ae8291dbf4828969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Mon, 1 Aug 2022 23:30:04 -0400 Subject: [PATCH] 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. --- .../react-dom/src/client/ReactDOMComponent.js | 12 +------- .../src/client/ReactDOMHostConfig.js | 15 ++-------- .../src/ReactFabricHostConfig.js | 3 -- .../src/ReactNativeHostConfig.js | 3 -- .../src/createReactNoop.js | 6 +--- .../src/ReactFiberCompleteWork.new.js | 30 +++---------------- .../src/ReactFiberCompleteWork.old.js | 30 +++---------------- .../src/ReactFiberHostContext.new.js | 5 +--- .../src/ReactFiberHostContext.old.js | 5 +--- .../src/ReactFiberHydrationContext.new.js | 2 -- .../src/ReactFiberHydrationContext.old.js | 2 -- .../src/ReactTestHostConfig.js | 1 - 12 files changed, 14 insertions(+), 100 deletions(-) diff --git a/packages/react-dom/src/client/ReactDOMComponent.js b/packages/react-dom/src/client/ReactDOMComponent.js index 19eb70e583b39..93c1534c235b4 100644 --- a/packages/react-dom/src/client/ReactDOMComponent.js +++ b/packages/react-dom/src/client/ReactDOMComponent.js @@ -283,7 +283,6 @@ export function trapClickOnNonInteractiveElement(node: HTMLElement) { function setInitialDOMProperties( tag: string, domElement: Element, - rootContainerElement: Element | Document | DocumentFragment, nextProps: Object, isCustomComponentTag: boolean, ): void { @@ -487,7 +486,6 @@ export function setInitialProperties( domElement: Element, tag: string, rawProps: Object, - rootContainerElement: Element | Document | DocumentFragment, ): void { const isCustomComponentTag = isCustomComponent(tag, rawProps); if (__DEV__) { @@ -571,13 +569,7 @@ export function setInitialProperties( assertValidProps(tag, props); - setInitialDOMProperties( - tag, - domElement, - rootContainerElement, - props, - isCustomComponentTag, - ); + setInitialDOMProperties(tag, domElement, props, isCustomComponentTag); switch (tag) { case 'input': @@ -613,7 +605,6 @@ export function diffProperties( tag: string, lastRawProps: Object, nextRawProps: Object, - rootContainerElement: Element | Document | DocumentFragment, ): null | Array { if (__DEV__) { validatePropertiesInDevelopment(tag, nextRawProps); @@ -866,7 +857,6 @@ export function diffHydratedProperties( tag: string, rawProps: Object, parentNamespace: string, - rootContainerElement: Element | Document | DocumentFragment, isConcurrentMode: boolean, shouldWarnDev: boolean, ): null | Array { diff --git a/packages/react-dom/src/client/ReactDOMHostConfig.js b/packages/react-dom/src/client/ReactDOMHostConfig.js index 3744bbdcdd370..12a14df0f1c14 100644 --- a/packages/react-dom/src/client/ReactDOMHostConfig.js +++ b/packages/react-dom/src/client/ReactDOMHostConfig.js @@ -181,7 +181,6 @@ export function getRootHostContext( export function getChildHostContext( parentHostContext: HostContext, type: string, - rootContainerInstance: Container, ): HostContext { if (__DEV__) { const parentHostContextDev = ((parentHostContext: any): HostContextDev); @@ -289,10 +288,9 @@ export function finalizeInitialChildren( domElement: Instance, type: string, props: Props, - rootContainerInstance: Container, hostContext: HostContext, ): boolean { - setInitialProperties(domElement, type, props, rootContainerInstance); + setInitialProperties(domElement, type, props); switch (type) { case 'button': case 'input': @@ -311,7 +309,6 @@ export function prepareUpdate( type: string, oldProps: Props, newProps: Props, - rootContainerInstance: Container, hostContext: HostContext, ): null | Array { if (__DEV__) { @@ -329,13 +326,7 @@ export function prepareUpdate( validateDOMNesting(null, string, ownAncestorInfo); } } - return diffProperties( - domElement, - type, - oldProps, - newProps, - rootContainerInstance, - ); + return diffProperties(domElement, type, oldProps, newProps); } export function shouldSetTextContent(type: string, props: Props): boolean { @@ -828,7 +819,6 @@ export function hydrateInstance( instance: Instance, type: string, props: Props, - rootContainerInstance: Container, hostContext: HostContext, internalInstanceHandle: Object, shouldWarnDev: boolean, @@ -855,7 +845,6 @@ export function hydrateInstance( type, props, parentNamespace, - rootContainerInstance, isConcurrentMode, shouldWarnDev, ); diff --git a/packages/react-native-renderer/src/ReactFabricHostConfig.js b/packages/react-native-renderer/src/ReactFabricHostConfig.js index 515c4e0f9665c..c5c029006578f 100644 --- a/packages/react-native-renderer/src/ReactFabricHostConfig.js +++ b/packages/react-native-renderer/src/ReactFabricHostConfig.js @@ -404,7 +404,6 @@ export function finalizeInitialChildren( parentInstance: Instance, type: string, props: Props, - rootContainerInstance: Container, hostContext: HostContext, ): boolean { return false; @@ -419,7 +418,6 @@ export function getRootHostContext( export function getChildHostContext( parentHostContext: HostContext, type: string, - rootContainerInstance: Container, ): HostContext { const prevIsInAParentText = parentHostContext.isInAParentText; const isInAParentText = @@ -453,7 +451,6 @@ export function prepareUpdate( type: string, oldProps: Props, newProps: Props, - rootContainerInstance: Container, hostContext: HostContext, ): null | Object { const viewConfig = instance.canonical.viewConfig; diff --git a/packages/react-native-renderer/src/ReactNativeHostConfig.js b/packages/react-native-renderer/src/ReactNativeHostConfig.js index 10c5e37f41bcc..5b03399e103f4 100644 --- a/packages/react-native-renderer/src/ReactNativeHostConfig.js +++ b/packages/react-native-renderer/src/ReactNativeHostConfig.js @@ -166,7 +166,6 @@ export function finalizeInitialChildren( parentInstance: Instance, type: string, props: Props, - rootContainerInstance: Container, hostContext: HostContext, ): boolean { // Don't send a no-op message over the bridge. @@ -199,7 +198,6 @@ export function getRootHostContext( export function getChildHostContext( parentHostContext: HostContext, type: string, - rootContainerInstance: Container, ): HostContext { const prevIsInAParentText = parentHostContext.isInAParentText; const isInAParentText = @@ -230,7 +228,6 @@ export function prepareUpdate( type: string, oldProps: Props, newProps: Props, - rootContainerInstance: Container, hostContext: HostContext, ): null | Object { return UPDATE_SIGNAL; diff --git a/packages/react-noop-renderer/src/createReactNoop.js b/packages/react-noop-renderer/src/createReactNoop.js index df2b3a839a521..858c562d48bf5 100644 --- a/packages/react-noop-renderer/src/createReactNoop.js +++ b/packages/react-noop-renderer/src/createReactNoop.js @@ -276,11 +276,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { return NO_CONTEXT; }, - getChildHostContext( - parentHostContext: HostContext, - type: string, - rootcontainerInstance: Container, - ) { + getChildHostContext(parentHostContext: HostContext, type: string) { if (type === 'offscreen') { return parentHostContext; } diff --git a/packages/react-reconciler/src/ReactFiberCompleteWork.new.js b/packages/react-reconciler/src/ReactFiberCompleteWork.new.js index e1d24857c93b3..7a8843941eee5 100644 --- a/packages/react-reconciler/src/ReactFiberCompleteWork.new.js +++ b/packages/react-reconciler/src/ReactFiberCompleteWork.new.js @@ -255,7 +255,6 @@ if (supportsMutation) { workInProgress: Fiber, type: Type, newProps: Props, - rootContainerInstance: Container, ) { // If we have an alternate, that means this is an update and we need to // schedule a side-effect to do the updates. @@ -280,7 +279,6 @@ if (supportsMutation) { type, oldProps, newProps, - rootContainerInstance, currentHostContext, ); // TODO: Type this specific to this type of component. @@ -458,7 +456,6 @@ if (supportsMutation) { workInProgress: Fiber, type: Type, newProps: Props, - rootContainerInstance: Container, ) { const currentInstance = current.stateNode; const oldProps = current.memoizedProps; @@ -480,7 +477,6 @@ if (supportsMutation) { type, oldProps, newProps, - rootContainerInstance, currentHostContext, ); } @@ -501,13 +497,7 @@ if (supportsMutation) { recyclableInstance, ); if ( - finalizeInitialChildren( - newInstance, - type, - newProps, - rootContainerInstance, - currentHostContext, - ) + finalizeInitialChildren(newInstance, type, newProps, currentHostContext) ) { markUpdate(workInProgress); } @@ -555,7 +545,6 @@ if (supportsMutation) { workInProgress: Fiber, type: Type, newProps: Props, - rootContainerInstance: Container, ) { // Noop }; @@ -964,16 +953,9 @@ function completeWork( } case HostComponent: { popHostContext(workInProgress); - const rootContainerInstance = getRootHostContainer(); const type = workInProgress.type; if (current !== null && workInProgress.stateNode != null) { - updateHostComponent( - current, - workInProgress, - type, - newProps, - rootContainerInstance, - ); + updateHostComponent(current, workInProgress, type, newProps); if (current.ref !== workInProgress.ref) { markRef(workInProgress); @@ -1002,17 +984,14 @@ function completeWork( // TODO: Move this and createInstance step into the beginPhase // to consolidate. if ( - prepareToHydrateHostInstance( - workInProgress, - rootContainerInstance, - currentHostContext, - ) + prepareToHydrateHostInstance(workInProgress, currentHostContext) ) { // If changes to the hydrated node need to be applied at the // commit-phase we mark this as such. markUpdate(workInProgress); } } else { + const rootContainerInstance = getRootHostContainer(); const instance = createInstance( type, newProps, @@ -1033,7 +1012,6 @@ function completeWork( instance, type, newProps, - rootContainerInstance, currentHostContext, ) ) { diff --git a/packages/react-reconciler/src/ReactFiberCompleteWork.old.js b/packages/react-reconciler/src/ReactFiberCompleteWork.old.js index 10f8e43e35bd8..1ff1a5173ec10 100644 --- a/packages/react-reconciler/src/ReactFiberCompleteWork.old.js +++ b/packages/react-reconciler/src/ReactFiberCompleteWork.old.js @@ -255,7 +255,6 @@ if (supportsMutation) { workInProgress: Fiber, type: Type, newProps: Props, - rootContainerInstance: Container, ) { // If we have an alternate, that means this is an update and we need to // schedule a side-effect to do the updates. @@ -280,7 +279,6 @@ if (supportsMutation) { type, oldProps, newProps, - rootContainerInstance, currentHostContext, ); // TODO: Type this specific to this type of component. @@ -458,7 +456,6 @@ if (supportsMutation) { workInProgress: Fiber, type: Type, newProps: Props, - rootContainerInstance: Container, ) { const currentInstance = current.stateNode; const oldProps = current.memoizedProps; @@ -480,7 +477,6 @@ if (supportsMutation) { type, oldProps, newProps, - rootContainerInstance, currentHostContext, ); } @@ -501,13 +497,7 @@ if (supportsMutation) { recyclableInstance, ); if ( - finalizeInitialChildren( - newInstance, - type, - newProps, - rootContainerInstance, - currentHostContext, - ) + finalizeInitialChildren(newInstance, type, newProps, currentHostContext) ) { markUpdate(workInProgress); } @@ -555,7 +545,6 @@ if (supportsMutation) { workInProgress: Fiber, type: Type, newProps: Props, - rootContainerInstance: Container, ) { // Noop }; @@ -964,16 +953,9 @@ function completeWork( } case HostComponent: { popHostContext(workInProgress); - const rootContainerInstance = getRootHostContainer(); const type = workInProgress.type; if (current !== null && workInProgress.stateNode != null) { - updateHostComponent( - current, - workInProgress, - type, - newProps, - rootContainerInstance, - ); + updateHostComponent(current, workInProgress, type, newProps); if (current.ref !== workInProgress.ref) { markRef(workInProgress); @@ -1002,17 +984,14 @@ function completeWork( // TODO: Move this and createInstance step into the beginPhase // to consolidate. if ( - prepareToHydrateHostInstance( - workInProgress, - rootContainerInstance, - currentHostContext, - ) + prepareToHydrateHostInstance(workInProgress, currentHostContext) ) { // If changes to the hydrated node need to be applied at the // commit-phase we mark this as such. markUpdate(workInProgress); } } else { + const rootContainerInstance = getRootHostContainer(); const instance = createInstance( type, newProps, @@ -1033,7 +1012,6 @@ function completeWork( instance, type, newProps, - rootContainerInstance, currentHostContext, ) ) { diff --git a/packages/react-reconciler/src/ReactFiberHostContext.new.js b/packages/react-reconciler/src/ReactFiberHostContext.new.js index e7d9433136ad9..282414a658cba 100644 --- a/packages/react-reconciler/src/ReactFiberHostContext.new.js +++ b/packages/react-reconciler/src/ReactFiberHostContext.new.js @@ -75,11 +75,8 @@ function getHostContext(): HostContext { } function pushHostContext(fiber: Fiber): void { - const rootInstance: Container = requiredContext( - rootInstanceStackCursor.current, - ); const context: HostContext = requiredContext(contextStackCursor.current); - const nextContext = getChildHostContext(context, fiber.type, rootInstance); + const nextContext = getChildHostContext(context, fiber.type); // Don't push this Fiber's context unless it's unique. if (context === nextContext) { diff --git a/packages/react-reconciler/src/ReactFiberHostContext.old.js b/packages/react-reconciler/src/ReactFiberHostContext.old.js index 667aeaf0ddefc..a4735b4bb6976 100644 --- a/packages/react-reconciler/src/ReactFiberHostContext.old.js +++ b/packages/react-reconciler/src/ReactFiberHostContext.old.js @@ -75,11 +75,8 @@ function getHostContext(): HostContext { } function pushHostContext(fiber: Fiber): void { - const rootInstance: Container = requiredContext( - rootInstanceStackCursor.current, - ); const context: HostContext = requiredContext(contextStackCursor.current); - const nextContext = getChildHostContext(context, fiber.type, rootInstance); + const nextContext = getChildHostContext(context, fiber.type); // Don't push this Fiber's context unless it's unique. if (context === nextContext) { diff --git a/packages/react-reconciler/src/ReactFiberHydrationContext.new.js b/packages/react-reconciler/src/ReactFiberHydrationContext.new.js index 141abb712c8f6..fd3f9b18a4921 100644 --- a/packages/react-reconciler/src/ReactFiberHydrationContext.new.js +++ b/packages/react-reconciler/src/ReactFiberHydrationContext.new.js @@ -444,7 +444,6 @@ function tryToClaimNextHydratableInstance(fiber: Fiber): void { function prepareToHydrateHostInstance( fiber: Fiber, - rootContainerInstance: Container, hostContext: HostContext, ): boolean { if (!supportsHydration) { @@ -460,7 +459,6 @@ function prepareToHydrateHostInstance( instance, fiber.type, fiber.memoizedProps, - rootContainerInstance, hostContext, fiber, shouldWarnIfMismatchDev, diff --git a/packages/react-reconciler/src/ReactFiberHydrationContext.old.js b/packages/react-reconciler/src/ReactFiberHydrationContext.old.js index 736463823d383..9ac9e4dc666b2 100644 --- a/packages/react-reconciler/src/ReactFiberHydrationContext.old.js +++ b/packages/react-reconciler/src/ReactFiberHydrationContext.old.js @@ -444,7 +444,6 @@ function tryToClaimNextHydratableInstance(fiber: Fiber): void { function prepareToHydrateHostInstance( fiber: Fiber, - rootContainerInstance: Container, hostContext: HostContext, ): boolean { if (!supportsHydration) { @@ -460,7 +459,6 @@ function prepareToHydrateHostInstance( instance, fiber.type, fiber.memoizedProps, - rootContainerInstance, hostContext, fiber, shouldWarnIfMismatchDev, diff --git a/packages/react-test-renderer/src/ReactTestHostConfig.js b/packages/react-test-renderer/src/ReactTestHostConfig.js index 840912db30886..e049c3500c700 100644 --- a/packages/react-test-renderer/src/ReactTestHostConfig.js +++ b/packages/react-test-renderer/src/ReactTestHostConfig.js @@ -128,7 +128,6 @@ export function getRootHostContext( export function getChildHostContext( parentHostContext: HostContext, type: string, - rootContainerInstance: Container, ): HostContext { return NO_CONTEXT; }