From 9b7094dcf2eaf3eaed6ca4f148a4793e2ca53729 Mon Sep 17 00:00:00 2001 From: Joe Allen <49467845+LiJoeAllen@users.noreply.github.com> Date: Tue, 18 Aug 2026 14:52:20 +0800 Subject: [PATCH] fix: auto-resubscribe persisted subscriptions on reconnect The topic tree subscriptions were persisted in localStorage but never re-subscribed when the connection was re-established. Now when mqtt:status fires with 'connected', all saved subscriptions for that connection are automatically re-subscribed. --- src/stores/useMqttBridge.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/stores/useMqttBridge.ts b/src/stores/useMqttBridge.ts index e348790..9e42842 100644 --- a/src/stores/useMqttBridge.ts +++ b/src/stores/useMqttBridge.ts @@ -14,6 +14,7 @@ import type { MqttMessage } from '../types/mqtt' import { useConnections } from './useConnections' import { useMessages } from './useMessages' import { useLogs } from './useLogs' +import { useSubscriptions } from './useSubscriptions' import type { LogEntry } from './useLogs' /** @@ -61,9 +62,18 @@ export function useMqttBridge() { case 'connecting': updateStatus(e.connection_id, 'connecting') break - case 'connected': + case 'connected': { updateStatus(e.connection_id, 'connected') + // Auto-resubscribe all persisted subscriptions for this connection + const { getSubscriptionsByConnection } = useSubscriptions() + const subs = getSubscriptionsByConnection(e.connection_id) + for (const sub of subs) { + mqttSubscribe({ connection_id: e.connection_id, topic: sub.topic, qos: sub.qos }).catch(() => { + // Silently ignore resubscribe errors — the user will see them in the log + }) + } break + } case 'disconnected': updateStatus(e.connection_id, 'disconnected') break