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.
Sebastian Markbåge committed
Dec 4, 2024 at 19:53 UTC
1c9b138714a69cd136a3d82769b1fd9a4b318953
1 file changed
+3
-8
packages/react-server/src/ReactFlightServer.js
+3
-8
@@ -213,11 +213,8 @@ function patchConsole(consoleInst: typeof console, methodName: string) {
213
1,
214
);
215
request.pendingChunks++;
216
- // We don't currently use this id for anything but we emit it so that we can later
217
- // refer to previous logs in debug info to associate them with a component.
218
- const id = request.nextChunkId++;
216
const owner: null | ReactComponentInfo = resolveOwner();
220
- emitConsoleChunk(request, id, methodName, owner, stack, arguments);
217
+ emitConsoleChunk(request, methodName, owner, stack, arguments);
218
}
219
// $FlowFixMe[prop-missing]
220
return originalMethod.apply(this, arguments);
@@ -3227,8 +3224,7 @@ function emitHintChunk<Code: HintCode>(
3224
model: HintModel<Code>,
3225
): void {
3226
const json: string = stringify(model);
3230
- const id = request.nextChunkId++;
3231
- const row = serializeRowHeader('H' + code, id) + json + '\n';
3227
+ const row = ':H' + code + json + '\n';
3228
const processedChunk = stringToChunk(row);
3229
request.completedHintChunks.push(processedChunk);
3230
}
@@ -3764,7 +3760,6 @@ function outlineConsoleValue(
3760
3761
function emitConsoleChunk(
3762
request: Request,
3767
- id: number,
3763
methodName: string,
3764
owner: null | ReactComponentInfo,
3765
stackTrace: ReactStackTrace,
@@ -3828,7 +3823,7 @@ function emitConsoleChunk(
3823
replacer,
3824
);
3825
}
3831
- const row = serializeRowHeader('W', id) + json + '\n';
3826
+ const row = ':W' + json + '\n';
3827
const processedChunk = stringToChunk(row);
3828
request.completedRegularChunks.push(processedChunk);
3829
}