Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): safer settings changed check #4029

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
},
Expand Down
Loading