Skip to content

Commit f2940a8

Browse files
committed
Clear fiber field from host instance on unmount
1 parent ff431b7 commit f2940a8

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ export function precacheFiberNode(
4040
(node: any)[internalInstanceKey] = hostInst;
4141
}
4242

43+
export function clearFiberNode(
44+
node: Instance | TextInstance | SuspenseInstance,
45+
): void {
46+
(node: any)[internalInstanceKey] = null;
47+
}
48+
4349
export function markContainerAsRoot(hostRoot: Fiber, node: Container): void {
4450
node[internalContainerInstanceKey] = hostRoot;
4551
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
precacheFiberNode,
2020
updateFiberProps,
2121
getClosestInstanceFromNode,
22+
clearFiberNode,
2223
} from './ReactDOMComponentTree';
2324
import {
2425
createElement,
@@ -522,8 +523,10 @@ function dispatchAfterDetachedBlur(target: HTMLElement): void {
522523

523524
export function beforeRemoveInstance(
524525
instance: Instance | TextInstance | SuspenseInstance,
525-
) {
526-
// TODO for ReactDOM.createEventInstance
526+
): void {
527+
// Clear the fiber off the instance, to help GC
528+
clearFiberNode(instance);
529+
// TODO handle ReactDOM.createEventInstance
527530
}
528531

529532
export function removeChild(

0 commit comments

Comments
 (0)