Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions src/data/process-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ export function processEvents(
}

case "update":
// This check is potentially required (??) due to an unsupported app
// structure (e.g. multiple roots) or otherwise invalid react code.
// Knock-on effects of this check are mitigated in `../ui/fiber-maps`
if (!fiberById.has(event.fiberId)) {
continue;
}

updateCount++;

fiber = fiberById.get(event.fiberId) as MessageFiber;
Expand Down
15 changes: 14 additions & 1 deletion src/ui/utils/fiber-maps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,20 @@ export const useFiberChildren = (
) => {
const { selectTree } = useFiberMaps();
const tree = selectTree(groupByParent, includeUnmounted);
const leaf = tree.getOrCreate(fiberId);
let leaf = tree.getOrCreate(fiberId);

// Requesting the root node (fiber 0) returns an invalid fiber?
// This state is potentially (??) introduced due to an unsupported app
// structure and a subsequent workaround in `../data/process-events`
if (!fiberId && leaf?.fiber == null) {
// find the next node in the tree with a valid fiber and children
for (const [activeFiberId, { fiber, firstChild }] of tree.nodes) {
if (fiber && firstChild) {
leaf = tree.getOrCreate(activeFiberId);
break;
}
}
}

const compute = React.useCallback(() => leaf.children || EMPTY_ARRAY, [leaf]);

Expand Down