Skip to content

Commit

Permalink
[utils] Update isPlainObject implementation
Browse files Browse the repository at this point in the history
This update adds support for checking plain object in non-v8/standard
runtimes as well (ie vercel edge-runtime)

Closes #36574 #39338
  • Loading branch information
brijeshb42 committed Nov 27, 2023
1 parent 553cf82 commit 4b68ad9
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/mui-utils/src/deepmerge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
function isObjectLike(value: unknown): value is Record<keyof any, unknown> {
return value != null && typeof value === 'object';
}

function getPrototypeOf(arg: unknown) {
return Object.getPrototypeOf(Object(arg));
}

const hasOwnProperty = Object.prototype.hasOwnProperty;

export function isPlainObject(item: unknown): item is Record<keyof any, unknown> {
return item !== null && typeof item === 'object' && item.constructor === Object;
if (!isObjectLike(item)) {
return false;
}
const proto = getPrototypeOf(item);
if (proto === null) {
return true;
}
const Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
return typeof Ctor === 'function' && Ctor instanceof Ctor;
}

export interface DeepmergeOptions {
Expand Down

0 comments on commit 4b68ad9

Please sign in to comment.