From 9b8d0d374b9f74bf4b5a75cd1adb961e39a5e8ef Mon Sep 17 00:00:00 2001 From: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com> Date: Mon, 9 Mar 2026 10:44:22 +0530 Subject: [PATCH 1/3] fix(sidebar): keep sidebar app activation exclusive after plugin install --- src/sidebarApps/index.js | 57 ++++++++++++++++++++++++----------- src/sidebarApps/sidebarApp.js | 5 ++- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/sidebarApps/index.js b/src/sidebarApps/index.js index f30c08a84..baf1681d9 100644 --- a/src/sidebarApps/index.js +++ b/src/sidebarApps/index.js @@ -35,12 +35,13 @@ function add( ) { currentSection ??= id; - const active = currentSection === id; const app = new SidebarApp(icon, id, title, initFunction, onSelected); - - app.active = active; - app.install(prepend); apps.push(app); + app.install(prepend); + + if (currentSection === id) { + setActiveApp(id); + } } /** @@ -55,10 +56,13 @@ function remove(id) { app.remove(); apps.splice(apps.indexOf(app), 1); if (wasActive && apps.length > 0) { - const firstApp = apps[0]; - firstApp.active = true; - currentSection = firstApp.id; - localStorage.setItem(SIDEBAR_APPS_LAST_SECTION, firstApp.id); + setActiveApp(apps[0].id); + return; + } + + if (!apps.length) { + currentSection = null; + localStorage.removeItem(SIDEBAR_APPS_LAST_SECTION); } } @@ -121,12 +125,16 @@ function setSponsorSidebarAppVisibility(visible) { * @returns {void} */ function ensureActiveApp() { - const hasActiveApp = apps.some((app) => app.active); - if (!hasActiveApp && apps.length > 0) { - const firstApp = apps[0]; - firstApp.active = true; - currentSection = firstApp.id; - localStorage.setItem(SIDEBAR_APPS_LAST_SECTION, firstApp.id); + const activeApps = apps.filter((app) => app.active); + if (activeApps.length === 1) return; + + if (activeApps.length > 1) { + setActiveApp(activeApps[0].id); + return; + } + + if (apps.length > 0) { + setActiveApp(apps[0].id); } } @@ -150,11 +158,24 @@ function onclick(e) { if (action !== "sidebar-app") return; - localStorage.setItem(SIDEBAR_APPS_LAST_SECTION, id); - const activeApp = apps.find((app) => app.active); + setActiveApp(id); +} + +/** + * Activates the given sidebar app and deactivates all others. + * @param {string} id + * @returns {void} + */ +function setActiveApp(id) { const app = apps.find((app) => app.id === id); - if (activeApp) activeApp.active = false; - if (app) app.active = true; + if (!app) return; + + currentSection = id; + localStorage.setItem(SIDEBAR_APPS_LAST_SECTION, id); + + for (const currentApp of apps) { + currentApp.active = currentApp.id === id; + } } export default { diff --git a/src/sidebarApps/sidebarApp.js b/src/sidebarApps/sidebarApp.js index df147dcdd..0c85339bc 100644 --- a/src/sidebarApps/sidebarApp.js +++ b/src/sidebarApps/sidebarApp.js @@ -86,7 +86,10 @@ export default class SidebarApp { /**@param {boolean} value */ set active(value) { - this.#active = !!value; + const nextValue = !!value; + if (this.#active === nextValue) return; + + this.#active = nextValue; this.#icon.classList.toggle("active", this.#active); if (this.#active) { const oldContainer = getContainer(this.#container); From 719c44d3e0a5d6c87bc9b18e58231d8b17e784ac Mon Sep 17 00:00:00 2001 From: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com> Date: Mon, 9 Mar 2026 10:49:47 +0530 Subject: [PATCH 2/3] fix --- src/sidebarApps/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sidebarApps/index.js b/src/sidebarApps/index.js index baf1681d9..30564544d 100644 --- a/src/sidebarApps/index.js +++ b/src/sidebarApps/index.js @@ -129,12 +129,16 @@ function ensureActiveApp() { if (activeApps.length === 1) return; if (activeApps.length > 1) { - setActiveApp(activeApps[0].id); + const preferredActiveApp = activeApps.find( + (app) => app.id === currentSection, + ); + setActiveApp(preferredActiveApp?.id || activeApps[0].id); return; } if (apps.length > 0) { - setActiveApp(apps[0].id); + const preferredApp = apps.find((app) => app.id === currentSection); + setActiveApp(preferredApp?.id || apps[0].id); } } From c656a9603d0545b14e8cfc335f995d233ea15f67 Mon Sep 17 00:00:00 2001 From: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com> Date: Mon, 9 Mar 2026 10:53:58 +0530 Subject: [PATCH 3/3] fix --- src/sidebarApps/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sidebarApps/index.js b/src/sidebarApps/index.js index 30564544d..363578e72 100644 --- a/src/sidebarApps/index.js +++ b/src/sidebarApps/index.js @@ -56,7 +56,8 @@ function remove(id) { app.remove(); apps.splice(apps.indexOf(app), 1); if (wasActive && apps.length > 0) { - setActiveApp(apps[0].id); + const preferredApp = apps.find((app) => app.id === currentSection); + setActiveApp(preferredApp?.id || apps[0].id); return; }