Skip to content

Commit 79124b2

Browse files
authored
Merge pull request #1428 from ryuapp/deep-equal-adapt-vnode
fix: deepEqual exceed maximum call stack size
2 parents 2d337e6 + 68724f4 commit 79124b2

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/util/deepEqual.ts

+25
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,31 @@ export function deepEqual<A, B>(obj1: A, obj2: B) {
3131
}
3232
return true;
3333
}
34+
// If objects are VNodes, compare their props only
35+
if (
36+
// eslint-disable-next-line no-prototype-builtins
37+
obj1.hasOwnProperty('constructor') &&
38+
// eslint-disable-next-line no-prototype-builtins
39+
obj2.hasOwnProperty('constructor') &&
40+
// eslint-disable-next-line no-prototype-builtins
41+
obj1.hasOwnProperty('props') &&
42+
// eslint-disable-next-line no-prototype-builtins
43+
obj2.hasOwnProperty('props') &&
44+
// eslint-disable-next-line no-prototype-builtins
45+
obj1.hasOwnProperty('key') &&
46+
// eslint-disable-next-line no-prototype-builtins
47+
obj2.hasOwnProperty('key') &&
48+
// eslint-disable-next-line no-prototype-builtins
49+
obj1.hasOwnProperty('ref') &&
50+
// eslint-disable-next-line no-prototype-builtins
51+
obj2.hasOwnProperty('ref') &&
52+
// eslint-disable-next-line no-prototype-builtins
53+
obj1.hasOwnProperty('type') &&
54+
// eslint-disable-next-line no-prototype-builtins
55+
obj2.hasOwnProperty('type')
56+
) {
57+
return deepEqual(obj1['props'], obj2['props']);
58+
}
3459
// If objects are both objects, compare their properties recursively
3560
const keys1 = Object.keys(obj1);
3661
const keys2 = Object.keys(obj2);

tests/jest/util/deepEqual.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { deepEqual } from '../../../src/util/deepEqual';
2+
import { html } from '../../../src/util/html';
23

34
describe('deepEqual', () => {
45
it('should return true when objects are the same', () => {
@@ -31,4 +32,12 @@ describe('deepEqual', () => {
3132
const result = deepEqual({ a: 42, c: fn }, { a: 42, c: fn });
3233
expect(result).toBeTrue();
3334
});
35+
36+
it('should return true when objects are VNodes', () => {
37+
const result = deepEqual(
38+
html('<span>Grid.js</span>'),
39+
html('<span>Grid.js</span>'),
40+
);
41+
expect(result).toBeTrue();
42+
});
3443
});

0 commit comments

Comments
 (0)