From 9b067a2791ae40f1cf3ef1cd1e23795fa0e9e5e6 Mon Sep 17 00:00:00 2001 From: Liang Gong Date: Sun, 24 Sep 2023 20:47:20 -0700 Subject: [PATCH] fix(core): do not mark FiberNode dominated by attached HTML element as unmounted Summary: This diff filters out a memory leak trace pattern: if a React FiberNode is dominated by an attached HTML DOM element. It is not considered as unmounted Fiber Node. Reviewed By: tulga1970 Differential Revision: D49250856 fbshipit-source-id: 46bdaf7d4cfb12e1d0b26e277483dccc2ba67fba --- packages/core/src/lib/Utils.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/core/src/lib/Utils.ts b/packages/core/src/lib/Utils.ts index 4ea655716..ad68b5334 100644 --- a/packages/core/src/lib/Utils.ts +++ b/packages/core/src/lib/Utils.ts @@ -586,7 +586,13 @@ function markDetachedFiberNode(node: IHeapNode): boolean { // if a Fiber node whose dominator is neither root nor // another Fiber node, then consider it as detached Fiber node if (cur.dominatorNode && cur.dominatorNode.id !== 1) { - if (!isFiberNode(cur.dominatorNode)) { + if ( + isDOMNodeIncomplete(cur.dominatorNode) && + !isDetachedDOMNode(cur.dominatorNode) + ) { + // skip the direct marking of detached DOM nodes here + // if the Fiber Node is dominated by an attached DOM element + } else if (!isFiberNode(cur.dominatorNode)) { cur.markAsDetached(); } }