Skip to content

Commit bbcc43d

Browse files
authored
[core] Fix deepmerge of DOM elements (#20100)
1 parent 1d20156 commit bbcc43d

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/material-ui-utils/src/deepmerge.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
export function isObject(item) {
2-
return item && typeof item === 'object' && !Array.isArray(item);
1+
export function isPlainObject(item) {
2+
return item && typeof item === 'object' && item.constructor === Object;
33
}
44

55
export default function deepmerge(target, source, options = { clone: true }) {
66
const output = options.clone ? { ...target } : target;
77

8-
if (isObject(target) && isObject(source)) {
8+
if (isPlainObject(target) && isPlainObject(source)) {
99
Object.keys(source).forEach(key => {
1010
// Avoid prototype pollution
1111
if (key === '__proto__') {
1212
return;
1313
}
1414

15-
if (isObject(source[key]) && key in target) {
15+
if (isPlainObject(source[key]) && key in target) {
1616
output[key] = deepmerge(target[key], source[key], options);
1717
} else {
1818
output[key] = source[key];

packages/material-ui-utils/src/deepmerge.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,14 @@ describe('deepmerge', () => {
99
});
1010
expect({}.isAdmin).to.equal(undefined);
1111
});
12+
13+
// https://github.com/mui-org/material-ui/issues/20095
14+
it('should not merge DOM elements', () => {
15+
const element = document.createElement('div');
16+
const element2 = document.createElement('div');
17+
18+
const result = deepmerge({ element }, { element: element2 });
19+
20+
expect(result.element).to.equal(element2);
21+
});
1222
});

0 commit comments

Comments
 (0)