Skip to content

Commit 35b2fda

Browse files
committed
fix(ui/daemon-client): prevent duplicate store subscribers on reconnect
Unsubscribe previous settings-change store subscriber before creating a new one in startNotifyDaemonOnParamsChange. This avoids accumulating duplicate subscribers across daemon reconnects and prevents repeated ConnectSettings notifications.
1 parent 7170756 commit 35b2fda

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

ui/src/daemon-client/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,20 @@ async function convertAndSyncOldSettings() {
702702
}
703703
}
704704

705-
async function startNotifyDaemonOnParamsChange() {
705+
var _unsubscribeNotifyDaemonOnParamsChange = null; // unsubscribe function for the store subscriber
706+
707+
async function startNotifyDaemonOnParamsChange() {
708+
// Unsubscribe any previously registered subscriber to avoid accumulating
709+
// duplicate subscribers across reconnects.
710+
if (_unsubscribeNotifyDaemonOnParamsChange) {
711+
_unsubscribeNotifyDaemonOnParamsChange();
712+
_unsubscribeNotifyDaemonOnParamsChange = null;
713+
}
714+
706715
var timerNotifyDaemonOnParamsChange = null;
707716

708717
// subscribe to changes in a store
709-
store.subscribe((mutation) => {
718+
_unsubscribeNotifyDaemonOnParamsChange = store.subscribe((mutation) => {
710719
try {
711720
switch (mutation.type) {
712721
case "settings/serverEntry":

0 commit comments

Comments
 (0)