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:
Csaba Tuncsik
2022-10-28 15:25:44 +02:00
committed by GitHub
parent 7620d93eda
commit ca60b0e203
2 changed files with 46 additions and 5 deletions

View File

@@ -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);
});
});