Skip to content

Commit

Permalink
clone json obj in relay flight client host config parser (facebook#20465
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
lunaruan authored and koto committed Jun 15, 2021
1 parent 9345cbd commit e2ac647
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,25 @@ function parseModelRecursively(response: Response, parentObj, value) {
}
if (typeof value === 'object' && value !== null) {
if (Array.isArray(value)) {
const parsedValue = [];
for (let i = 0; i < value.length; i++) {
(value: any)[i] = parseModelRecursively(response, value, value[i]);
(parsedValue: any)[i] = parseModelRecursively(
response,
value,
value[i],
);
}
return parseModelTuple(response, value);
return parseModelTuple(response, parsedValue);
} else {
const parsedValue = {};
for (const innerKey in value) {
(value: any)[innerKey] = parseModelRecursively(
(parsedValue: any)[innerKey] = parseModelRecursively(
response,
value,
value[innerKey],
);
}
return parsedValue;
}
}
return value;
Expand Down

0 comments on commit e2ac647

Please sign in to comment.