Drop stale live subscriptions across reconnects

This commit is contained in:
2026-09-20 18:53:06 -04:00
parent a112085686
commit 70be1ce75f
3 changed files with 32 additions and 22 deletions
@@ -1135,6 +1135,7 @@ class Te extends A {
_clockTimer; _clockTimer;
_unsubs = []; _unsubs = [];
_subscribed = !1; _subscribed = !1;
_subGeneration = 0;
setConfig(t) { setConfig(t) {
if (!t || typeof t != "object") if (!t || typeof t != "object")
throw new Error("Invalid configuration"); throw new Error("Invalid configuration");
@@ -1151,24 +1152,25 @@ class Te extends A {
if (!t) if (!t)
return; return;
this._subscribed = !0; this._subscribed = !0;
const e = (n) => { const e = ++this._subGeneration, n = (i) => {
n.then((i) => { i.then((r) => {
this._subscribed ? this._unsubs.push(i) : i(); this._subscribed && e === this._subGeneration ? this._unsubs.push(r) : r();
}).catch(() => { }).catch(() => {
}); });
}; };
for (const n of pe) for (const i of pe)
e( n(
t.subscribeEvents(() => this.requestUpdate(), n) t.subscribeEvents(() => this.requestUpdate(), i)
); );
e( n(
t.subscribeEvents((n) => { t.subscribeEvents((i) => {
const i = he(n); const r = he(i);
(i.startsWith("sensor.nestquest_") || i.startsWith("binary_sensor.nestquest_")) && this.requestUpdate(); (r.startsWith("sensor.nestquest_") || r.startsWith("binary_sensor.nestquest_")) && this.requestUpdate();
}, "state_changed") }, "state_changed")
); );
} }
_unsubscribeLive() { _unsubscribeLive() {
this._subGeneration++;
for (const t of this._unsubs) for (const t of this._unsubs)
t(); t();
this._unsubs = [], this._subscribed = !1; this._unsubs = [], this._subscribed = !1;
@@ -2726,6 +2728,7 @@ class un extends A {
_completeTimer; _completeTimer;
_unsubs = []; _unsubs = [];
_subscribed = !1; _subscribed = !1;
_subGeneration = 0;
setConfig(t) { setConfig(t) {
if (!t || typeof t != "object") if (!t || typeof t != "object")
throw new Error("Invalid configuration"); throw new Error("Invalid configuration");
@@ -2742,24 +2745,25 @@ class un extends A {
if (!t) if (!t)
return; return;
this._subscribed = !0; this._subscribed = !0;
const e = (n) => { const e = ++this._subGeneration, n = (i) => {
n.then((i) => { i.then((r) => {
this._subscribed ? this._unsubs.push(i) : i(); this._subscribed && e === this._subGeneration ? this._unsubs.push(r) : r();
}).catch(() => { }).catch(() => {
}); });
}; };
for (const n of Le) for (const i of Le)
e( n(
t.subscribeEvents(() => this.requestUpdate(), n) t.subscribeEvents(() => this.requestUpdate(), i)
); );
e( n(
t.subscribeEvents((n) => { t.subscribeEvents((i) => {
const i = De(n); const r = De(i);
(i.startsWith("sensor.nestquest_") || i.startsWith("binary_sensor.nestquest_")) && this.requestUpdate(); (r.startsWith("sensor.nestquest_") || r.startsWith("binary_sensor.nestquest_")) && this.requestUpdate();
}, "state_changed") }, "state_changed")
); );
} }
_unsubscribeLive() { _unsubscribeLive() {
this._subGeneration++;
for (const t of this._unsubs) for (const t of this._unsubs)
t(); t();
this._unsubs = [], this._subscribed = !1; this._unsubs = [], this._subscribed = !1;
+4 -1
View File
@@ -743,6 +743,7 @@ export class NestQuestPartyBoardCard extends LitElement {
private _clockTimer?: number; private _clockTimer?: number;
private _unsubs: Array<() => void> = []; private _unsubs: Array<() => void> = [];
private _subscribed = false; private _subscribed = false;
private _subGeneration = 0;
setConfig(config: CardConfig): void { setConfig(config: CardConfig): void {
if (!config || typeof config !== "object") { if (!config || typeof config !== "object") {
@@ -773,10 +774,11 @@ export class NestQuestPartyBoardCard extends LitElement {
return; return;
} }
this._subscribed = true; this._subscribed = true;
const token = ++this._subGeneration;
const track = (unsubPromise: Promise<() => void>): void => { const track = (unsubPromise: Promise<() => void>): void => {
unsubPromise unsubPromise
.then((unsub) => { .then((unsub) => {
if (this._subscribed) { if (this._subscribed && token === this._subGeneration) {
this._unsubs.push(unsub); this._unsubs.push(unsub);
} else { } else {
unsub(); unsub();
@@ -803,6 +805,7 @@ export class NestQuestPartyBoardCard extends LitElement {
} }
private _unsubscribeLive(): void { private _unsubscribeLive(): void {
this._subGeneration++;
for (const unsub of this._unsubs) { for (const unsub of this._unsubs) {
unsub(); unsub();
} }
+4 -1
View File
@@ -1389,6 +1389,7 @@ export class NestQuestQuestLogCard extends LitElement {
private _completeTimer?: number; private _completeTimer?: number;
private _unsubs: Array<() => void> = []; private _unsubs: Array<() => void> = [];
private _subscribed = false; private _subscribed = false;
private _subGeneration = 0;
setConfig(config: QuestLogCardConfig): void { setConfig(config: QuestLogCardConfig): void {
if (!config || typeof config !== "object") { if (!config || typeof config !== "object") {
@@ -1419,10 +1420,11 @@ export class NestQuestQuestLogCard extends LitElement {
return; return;
} }
this._subscribed = true; this._subscribed = true;
const token = ++this._subGeneration;
const track = (unsubPromise: Promise<() => void>): void => { const track = (unsubPromise: Promise<() => void>): void => {
unsubPromise unsubPromise
.then((unsub) => { .then((unsub) => {
if (this._subscribed) { if (this._subscribed && token === this._subGeneration) {
this._unsubs.push(unsub); this._unsubs.push(unsub);
} else { } else {
unsub(); unsub();
@@ -1449,6 +1451,7 @@ export class NestQuestQuestLogCard extends LitElement {
} }
private _unsubscribeLive(): void { private _unsubscribeLive(): void {
this._subGeneration++;
for (const unsub of this._unsubs) { for (const unsub of this._unsubs) {
unsub(); unsub();
} }