@samitouri / QOS-React / commits / 45f1a4a33f

DevTools: Revert force deep re-mount when Fast Refresh detected (#21539)

This reverts the most expensive part of 1e3383a41 (which seems to no longer be necessary after subsequent changes).

Brian Vaughn committed May 20, 2021 at 12:28 UTC 45f1a4a33f8e8015a80aeb18a813ee98cd989c6c
1 file changed +4 -23
packages/react-devtools-shared/src/backend/renderer.js
+4 -23
@@ -829,12 +829,6 @@ export function attach(
829 throw Error('Cannot modify filter preferences while profiling');
830 }
831
832 - unmountAndRemountAllRoots(() => {
833 - applyComponentFilters(componentFilters);
834 - });
835 - }
836 -
837 - function unmountAndRemountAllRoots(callback?: Function) {
832 // Recursively unmount all roots.
833 hook.getFiberRoots(rendererID).forEach(root => {
834 currentRootID = getOrGenerateFiberID(root.current);
@@ -846,9 +840,7 @@ export function attach(
840 currentRootID = -1;
841 });
842
849 - if (typeof callback === 'function') {
850 - callback();
851 - }
843 + applyComponentFilters(componentFilters);
844
845 // Reset pseudo counters so that new path selections will be persisted.
846 rootDisplayNameCounter.clear();
@@ -1797,20 +1789,6 @@ export function attach(
1789 );
1790 }
1791
1800 - const unsafeID = getFiberIDUnsafe(fiber);
1801 - if (fiber._debugNeedsRemount) {
1802 - if (unsafeID === null) {
1803 - // This inidicates a case we can't recover from:
1804 - // Fast Refresh has force remounted a component in a way that we don't have an id for.
1805 - // We could throw but that's a bad user experience.
1806 - // Or we could ignore the unmount but then Store might end up with a duplicate node.
1807 - // So a fallback is to completely reset the Store.
1808 - // This is costly but since Fast Refresh is only used in DEV builds, it should be okay.
1809 - setTimeout(unmountAndRemountAllRoots, 0);
1810 - return;
1811 - }
1812 - }
1813 -
1792 if (trackedPathMatchFiber !== null) {
1793 // We're in the process of trying to restore previous selection.
1794 // If this fiber matched but is being unmounted, there's no use trying.
@@ -1823,11 +1801,14 @@ export function attach(
1801 }
1802 }
1803
1804 + const unsafeID = getFiberIDUnsafe(fiber);
1805 if (unsafeID === null) {
1806 // If we've never seen this Fiber, it might be inside of a legacy render Suspense fragment (so the store is not even aware of it).
1807 // In that case we can just ignore it or it will cause errors later on.
1808 // One example of this is a Lazy component that never resolves before being unmounted.
1809 //
1810 + // This also might indicate a Fast Refresh force-remount scenario.
1811 + //
1812 // TODO: This is fragile and can obscure actual bugs.
1813 return;
1814 }