Fix notifications subscription leak when in narrow mode (#16953)

Fix persistent notifications subscription leak on mobile/narrow
This commit is contained in:
J. Nick Koston 2023-06-17 19:41:41 -05:00 committed by GitHub
parent 79c010eb7b
commit 2b51228665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,11 +74,16 @@ class HaMenuButton extends LitElement {
}
const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
const oldNarrow =
changedProps.get("narrow") ||
(oldHass && oldHass.dockedSidebar === "always_hidden");
const newNarrow =
this.narrow || this.hass.dockedSidebar === "always_hidden";
let oldNarrow: boolean | undefined;
let newNarrow: boolean | undefined;
if (changedProps.has("narrow")) {
oldNarrow = changedProps.get("narrow");
newNarrow = this.narrow;
} else if (oldHass) {
oldNarrow = oldHass.dockedSidebar === "always_hidden";
newNarrow = this.hass.dockedSidebar === "always_hidden";
}
if (oldNarrow === newNarrow) {
return;
@ -98,6 +103,9 @@ class HaMenuButton extends LitElement {
}
private _subscribeNotifications() {
if (this._unsubNotifications) {
throw new Error("Already subscribed");
}
this._unsubNotifications = subscribeNotifications(
this.hass.connection,
(notifications) => {