Skip to content

Commit

Permalink
Add and use a method to clear container
Browse files Browse the repository at this point in the history
  • Loading branch information
tyao1 committed Feb 24, 2023
1 parent 5fa8c1e commit db369d3
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/react-art/src/ReactARTHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,11 @@ export function preparePortalMount(portalInstance: any): void {
// noop
}

// eslint-disable-next-line no-undef
export function detachDeletedContainer(node: Container): void {
// noop
}

// eslint-disable-next-line no-undef
export function detachDeletedInstance(node: Instance): void {
// noop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ export function detachDeletedInstance(node: Instance): void {
delete (node: any)[internalEventHandlesSetKey];
}

export function detachDeletedContainer(node: Container): void {
delete (node: any)[internalContainerInstanceKey];
delete (node: any)[internalEventHandlersKey];
delete (node: any)[internalEventHandlerListenersKey];
delete (node: any)[internalEventHandlesSetKey];
}

export function precacheFiberNode(
hostInst: Fiber,
node: Instance | TextInstance | SuspenseInstance | ReactScopeInstance,
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dom-bindings/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import {
getFiberFromScopeInstance,
getInstanceFromNode as getInstanceFromNodeDOMTree,
isContainerMarkedAsRoot,
detachDeletedContainer,
detachDeletedInstance,
isMarkedResource,
markNodeAsResource,
} from './ReactDOMComponentTree';
export {detachDeletedInstance};
export {detachDeletedContainer, detachDeletedInstance};
import {hasRole} from './DOMAccessibilityRoles';
import {
createElement,
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,10 @@ export function preparePortalMount(portalInstance: Instance): void {
// noop
}

export function detachDeletedContainer(node: Container): void {
// noop
}

export function detachDeletedInstance(node: Instance): void {
// noop
}
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native-renderer/src/ReactNativeHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ export function preparePortalMount(portalInstance: Instance): void {
// noop
}

export function detachDeletedContainer(node: Container): void {
// noop
}

export function detachDeletedInstance(node: Instance): void {
// noop
}
Expand Down
2 changes: 2 additions & 0 deletions packages/react-noop-renderer/src/createReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
throw new Error('Not yet implemented.');
},

detachDeletedContainer() {},

detachDeletedInstance() {},

logRecoverableError() {
Expand Down
8 changes: 7 additions & 1 deletion packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ import {
prepareScopeUpdate,
prepareForCommit,
beforeActiveInstanceBlur,
detachDeletedContainer,
detachDeletedInstance,
clearSingleton,
acquireSingletonInstance,
Expand Down Expand Up @@ -1682,11 +1683,16 @@ function detachFiberAfterEffects(fiber: Fiber) {
// tree, which has its own pointers to children, parents, and siblings.
// The other host nodes also point back to fibers, so we should detach that
// one, too.
if (fiber.tag === HostComponent || fiber.tag === HostPortal) {
if (fiber.tag === HostComponent) {
const hostInstance: Instance = fiber.stateNode;
if (hostInstance !== null) {
detachDeletedInstance(hostInstance);
}
} else if (fiber.tag === HostPortal || fiber.tag === HostRoot) {
if (fiber.stateNode != null && fiber.stateNode.containerInfo != null) {
const hostContainer: Container = fiber.stateNode.containerInfo;
detachDeletedContainer(hostContainer);
}
}
fiber.stateNode = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const preparePortalMount = $$$hostConfig.preparePortalMount;
export const prepareScopeUpdate = $$$hostConfig.prepareScopeUpdate;
export const getInstanceFromScope = $$$hostConfig.getInstanceFromScope;
export const getCurrentEventPriority = $$$hostConfig.getCurrentEventPriority;
export const detachDeletedContainer = $$$hostConfig.detachDeletedContainer;
export const detachDeletedInstance = $$$hostConfig.detachDeletedInstance;
export const requestPostPaintCallback = $$$hostConfig.requestPostPaintCallback;
export const prepareRendererToRender = $$$hostConfig.prepareRendererToRender;
Expand Down
4 changes: 4 additions & 0 deletions packages/react-test-renderer/src/ReactTestHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ export function getInstanceFromScope(scopeInstance: Object): null | Object {
return nodeToInstanceMap.get(scopeInstance) || null;
}

export function detachDeletedContainer(node: Container): void {
// noop
}

export function detachDeletedInstance(node: Instance): void {
// noop
}
Expand Down

0 comments on commit db369d3

Please sign in to comment.