Skip to content

Commit 890fbd0

Browse files
committed
fix(ui): safer settings changed check
Fixes #4010
1 parent a0f9e0c commit 890fbd0

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/lib/utils.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,36 @@ export function deepEqual(a, b) {
170170
return a === b || JSON.stringify(a) === JSON.stringify(b)
171171
}
172172

173+
export function safeDeepEqual(a, b) {
174+
if (a === b) return true
175+
176+
if (typeof a !== 'object' || typeof b !== 'object') return false
177+
178+
if (Array.isArray(a) !== Array.isArray(b)) return false
179+
180+
if (Array.isArray(a)) {
181+
return arraysEqual(a, b)
182+
}
183+
184+
const keysA = Object.keys(a)
185+
const keysB = Object.keys(b)
186+
187+
if (keysA.length !== keysB.length) return false
188+
189+
for (const key of keysA) {
190+
if (!safeDeepEqual(a[key], b[key])) return false
191+
}
192+
193+
return true
194+
}
195+
173196
export function arraysEqual(a, b) {
174197
if (a === b) return true
175198
if (a == null || b == null) return false
176199
if (a.length !== b.length) return false
177200

178201
for (let i = 0; i < a.length; ++i) {
179-
if (a[i] !== b[i]) return false
202+
if (!safeDeepEqual(a[i], b[i])) return false
180203
}
181204

182205
return true

src/views/Settings.vue

+7-7
Original file line numberDiff line numberDiff line change
@@ -2046,7 +2046,7 @@
20462046
import { mapActions, mapState } from 'pinia'
20472047
import ConfigApis from '@/apis/ConfigApis'
20482048
import { parse } from 'native-url'
2049-
import { wait, copy, isUndef, deepEqual } from '../lib/utils'
2049+
import { wait, copy, isUndef, safeDeepEqual } from '../lib/utils'
20502050
import { rfRegions, znifferRegions } from '../lib/items'
20512051
import cronstrue from 'cronstrue'
20522052
import useBaseStore from '../stores/base'
@@ -2098,12 +2098,12 @@ export default {
20982098
},
20992099
},
21002100
settingsChanged() {
2101-
if (!deepEqual(this.newMqtt, this.mqtt)) return true
2102-
if (!deepEqual(this.newGateway, this.gateway)) return true
2103-
if (!deepEqual(this.newZwave, this.zwave)) return true
2104-
if (!deepEqual(this.newBackup, this.backup)) return true
2105-
if (!deepEqual(this.newZniffer, this.zniffer)) return true
2106-
if (!deepEqual(this.ui, this.prevUi)) return true
2101+
if (!safeDeepEqual(this.newMqtt, this.mqtt)) return true
2102+
if (!safeDeepEqual(this.newGateway, this.gateway)) return true
2103+
if (!safeDeepEqual(this.newZwave, this.zwave)) return true
2104+
if (!safeDeepEqual(this.newBackup, this.backup)) return true
2105+
if (!safeDeepEqual(this.newZniffer, this.zniffer)) return true
2106+
if (!safeDeepEqual(this.ui, this.prevUi)) return true
21072107
21082108
return false
21092109
},

0 commit comments

Comments
 (0)