Skip to content

Commit

Permalink
clone json obj in react native flight client host config parser (#20474)
Browse files Browse the repository at this point in the history
As per Seb's comment in #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 Dec 16, 2020
1 parent 4e62fd2 commit 9f338e5
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 9f338e5

Please sign in to comment.