Skip to content

Commit

Permalink
DevTools: Fix another Fast Refresh edge case
Browse files Browse the repository at this point in the history
Don't untrack unmounted Fibers after logging errors/warnings because it sometimes causes prematurely untracking a force-remounted Fiber from Fast Refresh, which in turn causes DevTools to break when the component is later inspected.

This is a hack but I'm not sure of a better workaround.
  • Loading branch information
Brian Vaughn committed May 20, 2021
1 parent ebcec3c commit 794ed49
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,7 @@ describe('TreeListContext', () => {
);

expect(state).toMatchInlineSnapshot(`
✕ 0, ⚠ 1
✕ 0, ⚠ 2
[root]
▾ <Suspense>
<Child> ⚠
Expand Down
5 changes: 4 additions & 1 deletion packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,10 @@ export function attach(
// We may also need to clean up after ourselves to avoid leaks.
// See inline comments in onErrorOrWarning() for more info.
if (isFiberMountedImpl(fiber) !== MOUNTED) {
untrackFiberID(fiber);
// HACK Cleaning up "unmounted" Fibers here can cause problems with Fast Refresh.
// Since warnings and errors are generally used in DEV mode,
// it may be better to ignore this kind of potential leak case rather than break Fast Refresh.
// untrackFiberID(fiber);
return;
}

Expand Down

0 comments on commit 794ed49

Please sign in to comment.