Skip to content

Commit e2ac647

Browse files
lunaruankoto
authored andcommitted
clone json obj in relay flight client host config parser (facebook#20465)
When `parseModel` suspends because of missing dependencies, it will exit and retry to parse later. However, in the relay implementation, the model is an object that we modify in place when we parse it, so when we we retry, part of the model might be parsed already into React elements, which will error because the parsing code expect a Flight model. This diff clones instead of mutating the original model, which fixes this error.
1 parent 9345cbd commit e2ac647

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/react-server-dom-relay/src/ReactFlightDOMRelayClientHostConfig.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,25 @@ function parseModelRecursively(response: Response, parentObj, value) {
3636
}
3737
if (typeof value === 'object' && value !== null) {
3838
if (Array.isArray(value)) {
39+
const parsedValue = [];
3940
for (let i = 0; i < value.length; i++) {
40-
(value: any)[i] = parseModelRecursively(response, value, value[i]);
41+
(parsedValue: any)[i] = parseModelRecursively(
42+
response,
43+
value,
44+
value[i],
45+
);
4146
}
42-
return parseModelTuple(response, value);
47+
return parseModelTuple(response, parsedValue);
4348
} else {
49+
const parsedValue = {};
4450
for (const innerKey in value) {
45-
(value: any)[innerKey] = parseModelRecursively(
51+
(parsedValue: any)[innerKey] = parseModelRecursively(
4652
response,
4753
value,
4854
value[innerKey],
4955
);
5056
}
57+
return parsedValue;
5158
}
5259
}
5360
return value;

0 commit comments

Comments
 (0)