Closed
Description
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?