Repository navigation
🐞 fix(cloneObject): keep the length of sparse arrays - #13834
Merged
bluebill1049 merged 2 commits intoOct 7, 2026
Merged
bluebill1049 merged 2 commits into
bluebill1049 merged 2 commits into
Conversation
Signed-off-by: Charan Rathore <[email protected]>
bluebill1049
approved these changes
Oct 7, 2026
bluebill1049
approved these changes
Oct 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
cloneObjectclones an array by starting from[]and copying own enumerable keys in afor...inloop. A sparse array such asnew Array(3)has no own keys, so the non-enumerablelengthnever transfers and the clone collapses to[]. Sparse arrays passed throughdefaultValuesorresetlose their length on the way back out ofgetValues.The fix allocates the copy with
new Array(data.length)so the length and holes survive, while the existing own-key loop still deep-copies the assigned slots.Added a regression spec covering a fully sparse array, trailing holes next to assigned values, and sparse arrays round-tripping through
defaultValuesandreset.Tests: the full Jest suite passes on this branch (129 suites, 1516 tests). tsc, eslint and prettier are clean.
Prepared with AI assistance; verified locally as described above.