Skip to content

Commit 52ea641

Browse files
authored
[Flight] Don't increase serializedSize for every recursive pass (#33123)
I noticed that we increase this in the recursive part of the algorithm. This would mean that we'd count a key more than once if it has Server Components inside it recursively resolving. This moves it out to where we enter from toJSON. Which is called once per JSON entry (and therefore once per key).
1 parent 3ec88e7 commit 52ea641

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/react-server/src/ReactFlightServer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,6 +2302,9 @@ function renderModel(
23022302
key: string,
23032303
value: ReactClientValue,
23042304
): ReactJSONValue {
2305+
// First time we're serializing the key, we should add it to the size.
2306+
serializedSize += key.length;
2307+
23052308
const prevKeyPath = task.keyPath;
23062309
const prevImplicitSlot = task.implicitSlot;
23072310
try {
@@ -2416,8 +2419,6 @@ function renderModelDestructive(
24162419
// Set the currently rendering model
24172420
task.model = value;
24182421

2419-
serializedSize += parentPropertyName.length;
2420-
24212422
// Special Symbol, that's very common.
24222423
if (value === REACT_ELEMENT_TYPE) {
24232424
return '$';

0 commit comments

Comments
 (0)