From 1c9b138714a69cd136a3d82769b1fd9a4b318953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Wed, 4 Dec 2024 19:53:20 -0500 Subject: [PATCH] Don't serialize chunk ids for Hint and Console rows (#31671) Hints and Console logs are side-effects and don't belong to any particular value. They're `void`. Therefore they don't need a row ID. In the current parsing scheme it's ok to omit the id. It just becomes `0` which is the initial value which is then unused for these row types. So it looks like: ``` :HP[...] :W[...] 0:{...} ``` We could patch the parsing to encode the tag in the ID so it's more like the ID is the target of the side-effect. ``` H:P[...] W:[...] 0:{...} ``` Or move the tagging to the beginning like it used to be. But this seems simple enough for now. --- packages/react-server/src/ReactFlightServer.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/react-server/src/ReactFlightServer.js b/packages/react-server/src/ReactFlightServer.js index 8b69c7a8036ef..9f15eabe0d029 100644 --- a/packages/react-server/src/ReactFlightServer.js +++ b/packages/react-server/src/ReactFlightServer.js @@ -213,11 +213,8 @@ function patchConsole(consoleInst: typeof console, methodName: string) { 1, ); request.pendingChunks++; - // We don't currently use this id for anything but we emit it so that we can later - // refer to previous logs in debug info to associate them with a component. - const id = request.nextChunkId++; const owner: null | ReactComponentInfo = resolveOwner(); - emitConsoleChunk(request, id, methodName, owner, stack, arguments); + emitConsoleChunk(request, methodName, owner, stack, arguments); } // $FlowFixMe[prop-missing] return originalMethod.apply(this, arguments); @@ -3227,8 +3224,7 @@ function emitHintChunk( model: HintModel, ): void { const json: string = stringify(model); - const id = request.nextChunkId++; - const row = serializeRowHeader('H' + code, id) + json + '\n'; + const row = ':H' + code + json + '\n'; const processedChunk = stringToChunk(row); request.completedHintChunks.push(processedChunk); } @@ -3764,7 +3760,6 @@ function outlineConsoleValue( function emitConsoleChunk( request: Request, - id: number, methodName: string, owner: null | ReactComponentInfo, stackTrace: ReactStackTrace, @@ -3828,7 +3823,7 @@ function emitConsoleChunk( replacer, ); } - const row = serializeRowHeader('W', id) + json + '\n'; + const row = ':W' + json + '\n'; const processedChunk = stringToChunk(row); request.completedRegularChunks.push(processedChunk); }