Fix collection size check in merge #1521
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1490
Records can have a size property (
collection.size
, in the existing code) that is independent of the calculated immutable Collectionsize
property; usingtoSeq()
ensures that the Collection.size property is checked instead. Also added a test case to verify the edge case that this resolves.In debugging the original issue, I found that adding
return this;
to the end of theRecordType
function in Record.js (https://github.com/facebook/immutable-js/blob/master/src/Record.js#L76) also deals with #1490. This is because that function was getting erroneously invoked frommergeIntoKeyedWith
when called on a record with{size: 0}
fromreturn collection.constructor(iters[0]);
, and adding the final return ensures thatcollection.constructor(iters[0])
still returns the correct thing. I wasn’t sure if there is any other code path that could lead to that function being invoked with the expectation of getting the record instance returned, but if so, I’d be happy to add the finalreturn this;
to this PR.