From 2b51228665b7247d4b4ea6d3ff0c2919fd30c2a6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 17 Jun 2023 19:41:41 -0500 Subject: [PATCH] Fix notifications subscription leak when in narrow mode (#16953) Fix persistent notifications subscription leak on mobile/narrow --- src/components/ha-menu-button.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/components/ha-menu-button.ts b/src/components/ha-menu-button.ts index b51dd78800..3bb80a0e04 100644 --- a/src/components/ha-menu-button.ts +++ b/src/components/ha-menu-button.ts @@ -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) => {