From ea9bf3bf188c084b659d4c2ff20cf592f0ce44d7 Mon Sep 17 00:00:00 2001 From: Kael Date: Tue, 27 Aug 2024 17:44:41 +1000 Subject: [PATCH] extract helper function and check for null prototype --- packages/vuetify/src/util/helpers.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/vuetify/src/util/helpers.ts b/packages/vuetify/src/util/helpers.ts index e2e981eea92..bd8eddea62e 100644 --- a/packages/vuetify/src/util/helpers.ts +++ b/packages/vuetify/src/util/helpers.ts @@ -135,6 +135,14 @@ export function isObject (obj: any): obj is Record { return obj !== null && typeof obj === 'object' && !Array.isArray(obj) } +export function isPlainObject (obj: any): obj is Record { + let proto + return obj !== null && typeof obj === 'object' && ( + (proto = Object.getPrototypeOf(obj)) === Object.prototype || + proto === null + ) +} + export function refElement (obj?: ComponentPublicInstance | HTMLElement): HTMLElement | undefined { if (obj && '$el' in obj) { const el = obj.$el as HTMLElement @@ -488,16 +496,13 @@ export function mergeDeep ( // Only continue deep merging if // both properties are plain objects - if ( - isObject(sourceProperty) && Object.getPrototypeOf(sourceProperty) === Object.prototype && - isObject(targetProperty) && Object.getPrototypeOf(targetProperty) === Object.prototype - ) { + if (isPlainObject(sourceProperty) && isPlainObject(targetProperty)) { out[key] = mergeDeep(sourceProperty, targetProperty, arrayFn) continue } - if (Array.isArray(sourceProperty) && Array.isArray(targetProperty) && arrayFn) { + if (arrayFn && Array.isArray(sourceProperty) && Array.isArray(targetProperty)) { out[key] = arrayFn(sourceProperty, targetProperty) continue