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

Skip to content

cloneDeep throws RangeError for Sets with circular references #3122

@ajgreenb

Description

@ajgreenb

If you have an Object containing a Set with a reference to the Object and you _.cloneDeep it, you get RangeError: Maximum call stack size exceeded. In the same situation, but with an Array instead of a Set, there's no problem. Here's how you can reproduce it:

var objSet = { x: new Set() };
objSet.x.add(objSet);
_.cloneDeep(objSet);
// RangeError: Maximum call stack size exceeded

var objArr = { x: [] };
objArr.x.push(objArr);
_.cloneDeep(objArr);
// Properly deep-cloned object

Seems like circular dependencies aren't properly handled when they're in Sets? From #2137 I saw that support for deep-cloning Sets, Maps, and Symbols was added at 24cef1a. Is this behavior expected? If not, I'd be happy to attempt a fix. Seems like I would need to patch the baseClone function?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions