Skip to content

Commit

Permalink
clone json obj in react native flight client host config parser (face…
Browse files Browse the repository at this point in the history
…book#20474)

As per Seb's comment in facebook#20465, we need to do the same thing in React Native as we do in Relay.

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 e2ac647 commit 15f3b35
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 15f3b35

Please sign in to comment.