Skip to content

Commit

Permalink
fix #2049 - dont try to modify frozen objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-marcacci committed Nov 15, 2017
1 parent 4763238 commit 3a29865
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/relay-runtime/util/recycleNodesInto.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,31 @@ function recycleNodesInto<T>(prevData: T, nextData: T): T {
const prevArray = Array.isArray(prevData) ? prevData : null;
const nextArray = Array.isArray(nextData) ? nextData : null;
if (prevArray && nextArray) {
const isFrozen = Object.isFrozen(nextArray);
canRecycle =
nextArray.reduce((wasEqual, nextItem, ii) => {
const prevValue = prevArray[ii];
const nextValue = recycleNodesInto(prevValue, nextItem);
if (nextValue !== nextArray[ii]) {
if (nextValue !== nextArray[ii] && !isFrozen) {
nextArray[ii] = nextValue;
}
return wasEqual && nextArray[ii] === prevArray[ii];
return wasEqual && nextValue === prevArray[ii];
}, true) && prevArray.length === nextArray.length;
} else if (!prevArray && !nextArray) {
// Assign local variables to preserve Flow type refinement.
const prevObject = prevData;
const nextObject = nextData;
const prevKeys = Object.keys(prevObject);
const nextKeys = Object.keys(nextObject);
const isFrozen = Object.isFrozen(nextObject);
canRecycle =
nextKeys.reduce((wasEqual, key) => {
const prevValue = prevObject[key];
const nextValue = recycleNodesInto(prevValue, nextObject[key]);
if (nextValue !== nextObject[key]) {
if (nextValue !== nextObject[key] && !isFrozen) {
nextObject[key] = nextValue;
}
return wasEqual && nextObject[key] === prevObject[key];
return wasEqual && nextValue === prevObject[key];
}, true) && prevKeys.length === nextKeys.length;
}
return canRecycle ? prevData : nextData;
Expand Down

0 comments on commit 3a29865

Please sign in to comment.