Registry Mirror
Skip to content

File tree

‎packages/react-server/src/ReactFlightServerConfigDebugNode.js‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,29 @@ export function initAsyncDebugInfo(): void {
208208
switch (node.tag) {
209209
case IO_NODE: {
210210
lastRanAwait = null;
211-
// Log the end time when we resolved the I/O. This can happen
212-
// more than once if it's a recurring resource like a connection.
211+
// Log the end time when we resolved the I/O.
213212
const ioNode: IONode = (node: any);
214-
ioNode.end = performance.now();
213+
if (ioNode.end < 0) {
214+
ioNode.end = performance.now();
215+
} else {
216+
// This can happen more than once if it's a recurring resource like a connection.
217+
// Even for single events like setTimeout, this can happen three times due to ticks
218+
// and microtasks each running its own scope.
219+
// To preserve each operation's separate end time, we create a clone of the IO node.
220+
// Any pre-existing reference will refer to the first resolution and any new resolutions
221+
// will refer to the new node.
222+
const clonedNode: IONode = {
223+
tag: IO_NODE,
224+
owner: ioNode.owner,
225+
stack: ioNode.stack,
226+
start: ioNode.start,
227+
end: performance.now(),
228+
promise: ioNode.promise,
229+
awaited: ioNode.awaited,
230+
previous: ioNode.previous,
231+
};
232+
pendingOperations.set(asyncId, clonedNode);
233+
}
215234
break;
216235
}
217236
case UNRESOLVED_AWAIT_NODE: {

0 commit comments

Comments
 (0)