Skip to content
Prev Previous commit
Next Next commit
Track the key path on the SuspenseBoundary
This is unfortunate that we need to add this to the render path in general
but this doesn't really cost anything extra in terms of allocations since
this object would live anyway so it's an extra field.
  • Loading branch information
sebmarkbage committed Aug 31, 2023
commit d58d26d4782eee4b8280a2d26614f8955eaa20b5
5 changes: 4 additions & 1 deletion packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ type SuspenseBoundary = {
byteSize: number, // used to determine whether to inline children boundaries.
fallbackAbortableTasks: Set<Task>, // used to cancel task on the fallback if the boundary completes or gets canceled.
resources: BoundaryResources,
keyPath: KeyNode,
};

export type Task = {
Expand Down Expand Up @@ -385,6 +386,7 @@ function pingTask(request: Request, task: Task): void {
function createSuspenseBoundary(
request: Request,
fallbackAbortableTasks: Set<Task>,
keyPath: KeyNode,
): SuspenseBoundary {
return {
id: UNINITIALIZED_SUSPENSE_BOUNDARY_ID,
Expand All @@ -397,6 +399,7 @@ function createSuspenseBoundary(
fallbackAbortableTasks,
errorDigest: null,
resources: createBoundaryResources(),
keyPath,
};
}

Expand Down Expand Up @@ -590,7 +593,7 @@ function renderSuspenseBoundary(
const content: ReactNodeList = props.children;

const fallbackAbortSet: Set<Task> = new Set();
const newBoundary = createSuspenseBoundary(request, fallbackAbortSet);
const newBoundary = createSuspenseBoundary(request, fallbackAbortSet, task.keyPath);
const insertionIndex = parentSegment.chunks.length;
// The children of the boundary segment is actually the fallback.
const boundarySegment = createPendingSegment(
Expand Down