diff --git a/src/lib/utils.js b/src/lib/utils.js index a639345207..0a7bdb9825 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -170,13 +170,36 @@ export function deepEqual(a, b) { return a === b || JSON.stringify(a) === JSON.stringify(b) } +export function safeDeepEqual(a, b) { + if (a === b) return true + + if (typeof a !== 'object' || typeof b !== 'object') return false + + if (Array.isArray(a) !== Array.isArray(b)) return false + + if (Array.isArray(a)) { + return arraysEqual(a, b) + } + + const keysA = Object.keys(a) + const keysB = Object.keys(b) + + if (keysA.length !== keysB.length) return false + + for (const key of keysA) { + if (!safeDeepEqual(a[key], b[key])) return false + } + + return true +} + export function arraysEqual(a, b) { if (a === b) return true if (a == null || b == null) return false if (a.length !== b.length) return false for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false + if (!safeDeepEqual(a[i], b[i])) return false } return true diff --git a/src/views/Settings.vue b/src/views/Settings.vue index 77a39c417c..ec40ad40b6 100644 --- a/src/views/Settings.vue +++ b/src/views/Settings.vue @@ -2046,7 +2046,7 @@ import { mapActions, mapState } from 'pinia' import ConfigApis from '@/apis/ConfigApis' import { parse } from 'native-url' -import { wait, copy, isUndef, deepEqual } from '../lib/utils' +import { wait, copy, isUndef, safeDeepEqual } from '../lib/utils' import { rfRegions, znifferRegions } from '../lib/items' import cronstrue from 'cronstrue' import useBaseStore from '../stores/base' @@ -2098,12 +2098,12 @@ export default { }, }, settingsChanged() { - if (!deepEqual(this.newMqtt, this.mqtt)) return true - if (!deepEqual(this.newGateway, this.gateway)) return true - if (!deepEqual(this.newZwave, this.zwave)) return true - if (!deepEqual(this.newBackup, this.backup)) return true - if (!deepEqual(this.newZniffer, this.zniffer)) return true - if (!deepEqual(this.ui, this.prevUi)) return true + if (!safeDeepEqual(this.newMqtt, this.mqtt)) return true + if (!safeDeepEqual(this.newGateway, this.gateway)) return true + if (!safeDeepEqual(this.newZwave, this.zwave)) return true + if (!safeDeepEqual(this.newBackup, this.backup)) return true + if (!safeDeepEqual(this.newZniffer, this.zniffer)) return true + if (!safeDeepEqual(this.ui, this.prevUi)) return true return false },