176
string | number /* key */,
177
Array<ResumableNode> /* children */,
178
SuspenseBoundaryID /* id */,
179
+ number /* rootSegmentID */,
180
];
181
182
type ReplayNode =
1958
request.renderState,
1959
request.resumableState,
1960
);
1961
+ boundary.rootSegmentID = request.nextSegmentId++;
1962
1963
const boundaryKeyPath = boundary.keyPath;
1964
if (boundaryKeyPath === null) {
1973
boundaryKeyPath[2],
1974
children,
1975
boundary.id,
1976
+ boundary.rootSegmentID,
1977
];
1978
trackedPostpones.workingMap.set(boundaryKeyPath, boundaryNode);
1979
addToReplayParent(boundaryNode, boundaryKeyPath[0], trackedPostpones);
2024
segment.children.push(newSegment);
2025
// Reset lastPushedText for current Segment since the new Segment "consumed" it
2026
segment.lastPushedText = false;
2024
- return segment;
2027
+ return newSegment;
2028
}
2029
2030
function spawnNewSuspendedTask(
2319
if (
2320
segment.chunks.length === 0 &&
2321
segment.children.length === 1 &&
2319
- segment.children[0].boundary === null
2322
+ segment.children[0].boundary === null &&
2323
+ // Typically the id would not be assigned yet but if it's a postponed segment it might be.
2324
+ segment.children[0].id === -1
2325
) {
2326
// This is an empty segment. There's nothing to write, so we can instead transfer the ID
2327
// to the child. That way any existing references point to the child.
2673
);
2674
} else if (boundary.status !== COMPLETED) {
2675
if (boundary.status === PENDING) {
2676
+ // For pending boundaries we lazily assign an ID to the boundary
2677
+ // and root segment.
2678
boundary.id = assignSuspenseBoundaryID(
2679
request.renderState,
2680
request.resumableState,
2681
);
2682
+ boundary.rootSegmentID = request.nextSegmentId++;
2683
}
2676
- // This boundary is still loading. Emit a pending suspense boundary wrapper.
2684
2678
- // Assign an ID to refer to the future content by.
2679
- boundary.rootSegmentID = request.nextSegmentId++;
2685
if (boundary.completedSegments.length > 0) {
2686
// If this is at least partially complete, we can queue it to be partially emitted early.
2687
request.partialBoundaries.push(boundary);
2688
}
2689
2690
+ // This boundary is still loading. Emit a pending suspense boundary wrapper.
2691
+
2692
/// This is the first time we should have referenced this ID.
2693
const id = boundary.id;
2694
2875
);
2876
}
2877
2878
+ return flushSegmentContainer(request, destination, segment);
2879
+ } else if (segmentID === boundary.rootSegmentID) {
2880
+ // When we emit postponed boundaries, we might have assigned the ID already
2881
+ // but it's still the root segment so we can't inject it into the parent yet.
2882
return flushSegmentContainer(request, destination, segment);
2883
} else {
2884
flushSegmentContainer(request, destination, segment);