@@ -5733,6 +5733,15 @@ export function attach(
57335733 // to a specific instance will have those appear in order of when that instance was discovered.
57345734 let hooksCacheKey: null | DevToolsInstance = null;
57355735 let hooksCache: null | HooksTree = null;
5736+ // Collect the stream entries with the highest byte offset and end time.
5737+ const streamEntries: Map<
5738+ Promise<mixed>,
5739+ {
5740+ asyncInfo: ReactAsyncInfo,
5741+ instance: DevToolsInstance,
5742+ hooks: null | HooksTree,
5743+ },
5744+ > = new Map();
57365745 suspenseNode.suspendedBy.forEach((set, ioInfo) => {
57375746 let parentNode = suspenseNode.parent;
57385747 while (parentNode !== null) {
@@ -5771,10 +5780,42 @@ export function attach(
57715780 }
57725781 }
57735782 }
5774- result.push(serializeAsyncInfo(asyncInfo, firstInstance, hooks));
5783+ const newIO = asyncInfo.awaited;
5784+ if (newIO.name === 'RSC stream' && newIO.value != null) {
5785+ const streamPromise = newIO.value;
5786+ // Special case RSC stream entries to pick the last entry keyed by the stream.
5787+ const existingEntry = streamEntries.get(streamPromise);
5788+ if (existingEntry === undefined) {
5789+ streamEntries.set(streamPromise, {
5790+ asyncInfo,
5791+ instance: firstInstance,
5792+ hooks,
5793+ });
5794+ } else {
5795+ const existingIO = existingEntry.asyncInfo.awaited;
5796+ if (
5797+ newIO !== existingIO &&
5798+ ((newIO.byteSize !== undefined &&
5799+ existingIO.byteSize !== undefined &&
5800+ newIO.byteSize > existingIO.byteSize) ||
5801+ newIO.end > existingIO.end)
5802+ ) {
5803+ // The new entry is later in the stream that the old entry. Replace it.
5804+ existingEntry.asyncInfo = asyncInfo;
5805+ existingEntry.instance = firstInstance;
5806+ existingEntry.hooks = hooks;
5807+ }
5808+ }
5809+ } else {
5810+ result.push(serializeAsyncInfo(asyncInfo, firstInstance, hooks));
5811+ }
57755812 }
57765813 }
57775814 });
5815+ // Add any deduped stream entries.
5816+ streamEntries.forEach(({asyncInfo, instance, hooks}) => {
5817+ result.push(serializeAsyncInfo(asyncInfo, instance, hooks));
5818+ });
57785819 return result;
57795820 }
57805821
0 commit comments