Skip to content

Commit cb23672

Browse files
author
Som Meaden
committed
Resolve fiber === null in certain app structures / conditions
- Resolves an issue in the event processing pipeline where fibers return null and result in a critical error (loading fails, event queue continues to grow) - Applies a band-aid solution to a "knock-on" effect of the fix that results in missing / invalid fibers in active trees / fiber maps, causing the UI render to fail in REMPL
1 parent 6f9307a commit cb23672

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/data/process-events.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ export function processEvents(
201201
}
202202

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

206213
fiber = fiberById.get(event.fiberId) as MessageFiber;

src/ui/utils/fiber-maps.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,20 @@ export const useFiberChildren = (
7575
) => {
7676
const { selectTree } = useFiberMaps();
7777
const tree = selectTree(groupByParent, includeUnmounted);
78-
const leaf = tree.getOrCreate(fiberId);
78+
let leaf = tree.getOrCreate(fiberId);
79+
80+
// Requesting the root node (fiber 0) returns an invalid fiber?
81+
// This state is potentially (??) introduced due to an unsupported app
82+
// structure and a subsequent workaround in `../data/process-events`
83+
if (!fiberId && leaf?.fiber == null) {
84+
// find the next node in the tree with a valid fiber and children
85+
for (const [activeFiberId, { fiber, firstChild }] of tree.nodes) {
86+
if (fiber && firstChild) {
87+
leaf = tree.getOrCreate(activeFiberId);
88+
break;
89+
}
90+
}
91+
}
7992

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

0 commit comments

Comments
 (0)