From f50ff357cf45d5cbda8d5a99c247e33b0477e936 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 17 Sep 2021 12:53:07 -0400 Subject: [PATCH] DevTools: Fix memory leak via alternate Fiber pointer (#22346) --- packages/react-devtools-shared/src/backend/renderer.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/react-devtools-shared/src/backend/renderer.js b/packages/react-devtools-shared/src/backend/renderer.js index 3f03315fa5ce7..1cfcaaa6a866b 100644 --- a/packages/react-devtools-shared/src/backend/renderer.js +++ b/packages/react-devtools-shared/src/backend/renderer.js @@ -1140,6 +1140,13 @@ export function attach( untrackFibersSet.add(fiber); + // React may detach alternate pointers during unmount; + // Since our untracking code is async, we should explicily track the pending alternate here as well. + const alternate = fiber.alternate; + if (alternate !== null) { + untrackFibersSet.add(alternate); + } + if (untrackFibersTimeoutID === null) { untrackFibersTimeoutID = setTimeout(untrackFibers, 1000); }