Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DevTools] Delete fiberToFiberInstanceMap #30900

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 1 addition & 43 deletions packages/react-devtools-shared/src/backend/fiber/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,13 +744,7 @@ const knownEnvironmentNames: Set<string> = new Set();
// Map of FiberRoot to their root FiberInstance.
const rootToFiberInstanceMap: Map<FiberRoot, FiberInstance> = new Map();

// Map of one or more Fibers in a pair to their unique id number.
// We track both Fibers to support Fast Refresh,
// which may forcefully replace one of the pair as part of hot reloading.
// In that case it's still important to be able to locate the previous ID during subsequent renders.
const fiberToFiberInstanceMap: Map<Fiber, FiberInstance> = new Map();

// Map of id to one (arbitrary) Fiber in a pair.
// Map of id to FiberInstance or VirtualInstance.
// This Map is used to e.g. get the display name for a Fiber or schedule an update,
// operations that should be the same whether the current and work-in-progress Fiber is used.
const idToDevToolsInstanceMap: Map<number, FiberInstance | VirtualInstance> =
Expand Down Expand Up @@ -1327,14 +1321,9 @@ export function attach(
// Recursively re-mount all roots with new filter criteria applied.
hook.getFiberRoots(rendererID).forEach(root => {
const current = root.current;
const alternate = current.alternate;
const newRoot = createFiberInstance(current);
rootToFiberInstanceMap.set(root, newRoot);
idToDevToolsInstanceMap.set(newRoot.id, newRoot);
fiberToFiberInstanceMap.set(current, newRoot);
if (alternate) {
fiberToFiberInstanceMap.set(alternate, newRoot);
}

// Before the traversals, remember to start tracking
// our path in case we have selection to restore.
Expand Down Expand Up @@ -2016,14 +2005,6 @@ export function attach(
} else {
fiberInstance = createFiberInstance(fiber);
}
// If this already exists behind a different FiberInstance, we intentionally
// override it here to claim the fiber as part of this new instance.
// E.g. if it was part of a reparenting.
fiberToFiberInstanceMap.set(fiber, fiberInstance);
const alternate = fiber.alternate;
if (alternate !== null && fiberToFiberInstanceMap.has(alternate)) {
fiberToFiberInstanceMap.set(alternate, fiberInstance);
}
idToDevToolsInstanceMap.set(fiberInstance.id, fiberInstance);

const id = fiberInstance.id;
Expand Down Expand Up @@ -2237,16 +2218,6 @@ export function attach(

idToDevToolsInstanceMap.delete(fiberInstance.id);

if (fiberToFiberInstanceMap.get(fiber) === fiberInstance) {
fiberToFiberInstanceMap.delete(fiber);
}
const {alternate} = fiber;
if (alternate !== null) {
if (fiberToFiberInstanceMap.get(alternate) === fiberInstance) {
fiberToFiberInstanceMap.delete(alternate);
}
}

untrackFiber(fiberInstance, fiber);
}

Expand Down Expand Up @@ -3084,9 +3055,6 @@ export function attach(
shouldResetChildren = true;
}

// Register the new alternate in case it's not already in.
fiberToFiberInstanceMap.set(nextChild, fiberInstance);

moveChild(fiberInstance, previousSiblingOfExistingInstance);

if (
Expand Down Expand Up @@ -3467,11 +3435,6 @@ export function attach(
const newRoot = createFiberInstance(current);
rootToFiberInstanceMap.set(root, newRoot);
idToDevToolsInstanceMap.set(newRoot.id, newRoot);
fiberToFiberInstanceMap.set(current, newRoot);
const alternate = current.alternate;
if (alternate) {
fiberToFiberInstanceMap.set(alternate, newRoot);
}
currentRoot = newRoot;
setRootPseudoKey(currentRoot.id, root.current);

Expand Down Expand Up @@ -3541,11 +3504,6 @@ export function attach(
rootInstance = createFiberInstance(current);
rootToFiberInstanceMap.set(root, rootInstance);
idToDevToolsInstanceMap.set(rootInstance.id, rootInstance);
fiberToFiberInstanceMap.set(current, rootInstance);
const alternate = current.alternate;
if (alternate) {
fiberToFiberInstanceMap.set(alternate, rootInstance);
}
} else {
prevFiber = rootInstance.data;
}
Expand Down
Loading