Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix cloneDeep Map key cloning#6229

Open
puneetdixit200 wants to merge 1 commit into
lodash:mainfrom
puneetdixit200:fix-clonedeep-map-keys
Open

Fix cloneDeep Map key cloning#6229
puneetdixit200 wants to merge 1 commit into
lodash:mainfrom
puneetdixit200:fix-clonedeep-map-keys

Conversation

@puneetdixit200

Copy link
Copy Markdown

Fixes #6228.

Summary

  • clone Map keys through the same deep-clone path used for Set entries and Map values
  • keep the existing stack so shared and circular references are preserved while cloning Map entries
  • add regression coverage for object Map keys with nested objects

Checks

  • direct Node regression: current HEAD reused the Map key/nested object (true true), patched build clones both and preserves the old nested value (false false 1)
  • npm run style:main
  • npm run test:main (6,828 passing, 0 failing)
  • git diff --check

Notes

  • npm run style:test and direct jscs test/test.js were attempted, but the legacy JSCS process did not complete locally under Node v24.15.0.

@ljharb ljharb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a breaking change; we can't do it by default.

@Ap-0007 Ap-0007 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great fix! Cloning the keys in a Map is essential for a true deep clone, especially since Map keys are often complex objects themselves. The test cases clearly demonstrate the issue and the fix. Looks solid to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_.cloneDeep does not deep clone Map keys (only values)

4 participants