mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(core): updating deepCopy to avoid max callstack with circular deps (#4468)
* fix(core): updating deepCopy to avoid max callstack in case of circular dep * fix(core): show warning with path added to circular reference
This commit is contained in:
@@ -48,4 +48,40 @@ describe('deepCopy', () => {
|
||||
expect(copy.deep.props).toEqual(object.deep.props);
|
||||
expect(copy.deep.props).not.toBe(object.deep.props);
|
||||
});
|
||||
|
||||
it('should avoid max call stack in case of circular deps', () => {
|
||||
const object: Record<string, any> = {
|
||||
deep: {
|
||||
props: {
|
||||
list: [{ a: 1 }, { b: 2 }, { c: 3 }],
|
||||
},
|
||||
arr: [1, 2, 3],
|
||||
},
|
||||
arr: [
|
||||
{
|
||||
prop: {
|
||||
list: ['a', 'b', 'c'],
|
||||
},
|
||||
},
|
||||
],
|
||||
func: () => {},
|
||||
date: new Date(),
|
||||
undef: undefined,
|
||||
nil: null,
|
||||
bool: true,
|
||||
num: 1,
|
||||
};
|
||||
|
||||
object.circular = object;
|
||||
object.deep.props.circular = object;
|
||||
object.deep.arr.push(object)
|
||||
|
||||
const copy = deepCopy(object);
|
||||
expect(copy).toEqual(object);
|
||||
expect(copy).not.toBe(object);
|
||||
expect(copy.arr).toEqual(object.arr);
|
||||
expect(copy.arr).not.toBe(object.arr);
|
||||
expect(copy.deep.props).toEqual(object.deep.props);
|
||||
expect(copy.deep.props).not.toBe(object.deep.props);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user