Skip to content

Commit

Permalink
Pass instance to recordUnmount
Browse files Browse the repository at this point in the history
We're no longer looking it up and we know it exists.
  • Loading branch information
sebmarkbage committed Aug 13, 2024
1 parent f6d24e1 commit feb8ccd
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions packages/react-devtools-shared/src/backend/fiber/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2184,7 +2184,8 @@ export function attach(
return fiberInstance;
}

function recordUnmount(fiber: Fiber): null | FiberInstance {
function recordUnmount(fiberInstance: FiberInstance): void {
const fiber = fiberInstance.data;
if (__DEBUG__) {
debug('recordUnmount()', fiber, null);
}
Expand All @@ -2201,25 +2202,13 @@ export function attach(
}
}

const fiberInstance = getFiberInstanceUnsafe(fiber);
if (fiberInstance === null) {
// 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).
// In that case we can just ignore it or it will cause errors later on.
// One example of this is a Lazy component that never resolves before being unmounted.
//
// This also might indicate a Fast Refresh force-remount scenario.
//
// TODO: This is fragile and can obscure actual bugs.
return null;
}

const id = fiberInstance.id;
const isRoot = fiber.tag === HostRoot;
if (isRoot) {
// Roots must be removed only after all children have been removed.
// So we track it separately.
pendingUnmountedRootID = id;
} else if (!shouldFilterFiber(fiber)) {
} else {
// To maintain child-first ordering,
// we'll push it into one of these queues,
// and later arrange them in the correct order.
Expand All @@ -2233,7 +2222,6 @@ export function attach(
idToRootMap.delete(id);
idToTreeBaseDurationMap.delete(id);
}
return fiberInstance;
}

// Running state of the remaining children from the previous version of this parent that
Expand Down Expand Up @@ -2456,7 +2444,7 @@ export function attach(
remainingReconcilingChildren = stashedRemaining;
}
if (instance.kind === FIBER_INSTANCE) {
recordUnmount(instance.data);
recordUnmount(instance);
}
removeChild(instance);
}
Expand Down

0 comments on commit feb8ccd

Please sign in to comment.