[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).
This commit is contained in:
Sebastian Markbåge
2025-05-05 11:37:39 -04:00
committed by GitHub
parent 3ec88e797f
commit 52ea641449
+3 -2
View File
@@ -2302,6 +2302,9 @@ function renderModel(
key: string,
value: ReactClientValue,
): ReactJSONValue {
// First time we're serializing the key, we should add it to the size.
serializedSize += key.length;
const prevKeyPath = task.keyPath;
const prevImplicitSlot = task.implicitSlot;
try {
@@ -2416,8 +2419,6 @@ function renderModelDestructive(
// Set the currently rendering model
task.model = value;
serializedSize += parentPropertyName.length;
// Special Symbol, that's very common.
if (value === REACT_ELEMENT_TYPE) {
return '$';