Skip to content

Commit 082a690

Browse files
authored
[DevTools] Compute new reordered child set from the instance tree (#30668)
This is already filtered and simply just all the ids in the linked list. Same principle as #30665.
1 parent e865fe0 commit 082a690

File tree

1 file changed

+16
-53
lines changed
  • packages/react-devtools-shared/src/backend/fiber

1 file changed

+16
-53
lines changed

packages/react-devtools-shared/src/backend/fiber/renderer.js

+16-53
Original file line numberDiff line numberDiff line change
@@ -2516,24 +2516,28 @@ export function attach(
25162516
}
25172517
}
25182518

2519-
function recordResetChildren(
2520-
parentInstance: DevToolsInstance,
2521-
childSet: Fiber,
2522-
) {
2519+
function recordResetChildren(parentInstance: DevToolsInstance) {
25232520
if (__DEBUG__) {
2524-
debug('recordResetChildren()', childSet, parentInstance);
2521+
if (
2522+
parentInstance.firstChild !== null &&
2523+
parentInstance.firstChild.kind === FIBER_INSTANCE
2524+
) {
2525+
debug(
2526+
'recordResetChildren()',
2527+
parentInstance.firstChild.data,
2528+
parentInstance,
2529+
);
2530+
}
25252531
}
25262532
// The frontend only really cares about the displayName, key, and children.
25272533
// The first two don't really change, so we are only concerned with the order of children here.
25282534
// This is trickier than a simple comparison though, since certain types of fibers are filtered.
25292535
const nextChildren: Array<number> = [];
25302536

2531-
// This is a naive implementation that shallowly recourses children.
2532-
// We might want to revisit this if it proves to be too inefficient.
2533-
let child: null | Fiber = childSet;
2537+
let child: null | DevToolsInstance = parentInstance.firstChild;
25342538
while (child !== null) {
2535-
findReorderedChildrenRecursively(child, nextChildren);
2536-
child = child.sibling;
2539+
nextChildren.push(child.id);
2540+
child = child.nextSibling;
25372541
}
25382542

25392543
const numChildren = nextChildren.length;
@@ -2549,38 +2553,6 @@ export function attach(
25492553
}
25502554
}
25512555

2552-
function findReorderedChildrenRecursively(
2553-
fiber: Fiber,
2554-
nextChildren: Array<number>,
2555-
) {
2556-
if (!shouldFilterFiber(fiber)) {
2557-
nextChildren.push(getFiberIDThrows(fiber));
2558-
} else {
2559-
let child = fiber.child;
2560-
const isTimedOutSuspense =
2561-
fiber.tag === SuspenseComponent && fiber.memoizedState !== null;
2562-
if (isTimedOutSuspense) {
2563-
// Special case: if Suspense mounts in a timed-out state,
2564-
// get the fallback child from the inner fragment,
2565-
// and skip over the primary child.
2566-
const primaryChildFragment = fiber.child;
2567-
const fallbackChildFragment = primaryChildFragment
2568-
? primaryChildFragment.sibling
2569-
: null;
2570-
const fallbackChild = fallbackChildFragment
2571-
? fallbackChildFragment.child
2572-
: null;
2573-
if (fallbackChild !== null) {
2574-
child = fallbackChild;
2575-
}
2576-
}
2577-
while (child !== null) {
2578-
findReorderedChildrenRecursively(child, nextChildren);
2579-
child = child.sibling;
2580-
}
2581-
}
2582-
}
2583-
25842556
// Returns whether closest unfiltered fiber parent needs to reset its child list.
25852557
function updateChildrenRecursively(
25862558
nextFirstChild: null | Fiber,
@@ -2865,17 +2837,8 @@ export function attach(
28652837
// We need to crawl the subtree for closest non-filtered Fibers
28662838
// so that we can display them in a flat children set.
28672839
if (shouldIncludeInTree) {
2868-
// Normally, search for children from the rendered child.
2869-
let nextChildSet = nextFiber.child;
2870-
if (nextDidTimeOut) {
2871-
// Special case: timed-out Suspense renders the fallback set.
2872-
const nextFiberChild = nextFiber.child;
2873-
nextChildSet = nextFiberChild ? nextFiberChild.sibling : null;
2874-
}
2875-
if (nextChildSet != null) {
2876-
if (reconcilingParent !== null) {
2877-
recordResetChildren(reconcilingParent, nextChildSet);
2878-
}
2840+
if (reconcilingParent !== null) {
2841+
recordResetChildren(reconcilingParent);
28792842
}
28802843
// We've handled the child order change for this Fiber.
28812844
// Since it's included, there's no need to invalidate parent child order.

0 commit comments

Comments
 (0)