Skip to content

fix(sidebar): keep sidebar app activation exclusive after plugin install#1932

Merged
bajrangCoder merged 3 commits intoAcode-Foundation:mainfrom
bajrangCoder:fix/sidebar-app-activation
Mar 9, 2026
Merged

fix(sidebar): keep sidebar app activation exclusive after plugin install#1932
bajrangCoder merged 3 commits intoAcode-Foundation:mainfrom
bajrangCoder:fix/sidebar-app-activation

Conversation

@bajrangCoder
Copy link
Member

No description provided.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 9, 2026

Greptile Summary

This PR fixes a bug where installing a sidebar plugin app could leave multiple sidebar icons in the "active" state simultaneously by centralizing all activation logic into a new setActiveApp helper that enforces mutual exclusion.

Key changes:

  • New setActiveApp(id) helper (index.js): Iterates over all registered apps, activating only the one matching id and deactivating the rest. All previous call-sites that set app.active directly are replaced with this function.
  • add function fix (index.js): Instead of directly assigning app.active = true (which never deactivated the previously active app), it now calls setActiveApp(id) so that the newly added plugin app can only become active by deactivating all others.
  • remove function improvement (index.js): Uses setActiveApp for the "activate next app" path, and properly handles the edge case where the last app is removed by clearing currentSection from localStorage.
  • ensureActiveApp expansion (index.js): Now handles the "multiple active apps" invariant violation (a leftover from the old code) in addition to the "no active apps" case.
  • SidebarApp.active setter optimization (sidebarApp.js): Adds an early-exit guard when the value hasn't changed, preventing unnecessary DOM class-toggle operations.

Confidence Score: 4/5

  • This PR is safe to merge with one minor logic concern in the deduplication path of ensureActiveApp.
  • The refactor is well-structured and clearly fixes the stated bug. All active-app mutations are now routed through setActiveApp, making the flow easier to reason about. The one issue — not honoring currentSection in the multi-active deduplication branch — is an edge case that shouldn't occur in normal operation with the new code, but could manifest when recovering from state corrupted by the old code.
  • Pay attention to src/sidebarApps/index.js lines 131-133 (ensureActiveApp multi-active deduplication).

Important Files Changed

Filename Overview
src/sidebarApps/index.js Refactors active-app management into a centralized setActiveApp helper, fixing the exclusive-activation bug on plugin install. One minor logic issue: ensureActiveApp doesn't respect currentSection when deduplicating multiple active apps.
src/sidebarApps/sidebarApp.js Adds an early-exit guard to the active setter to skip redundant DOM operations when the value hasn't changed. Clean, safe optimization.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant index.js
    participant setActiveApp
    participant SidebarApp

    Note over index.js: Plugin install / loadApps()
    Caller->>index.js: add(icon, id, ...)
    index.js->>SidebarApp: new SidebarApp(...)
    index.js->>index.js: apps.push(app)
    index.js->>SidebarApp: app.install(prepend)
    alt currentSection === id
        index.js->>setActiveApp: setActiveApp(id)
        setActiveApp->>SidebarApp: app.active = true (matched)
        setActiveApp->>SidebarApp: app.active = false (others)
    end

    Note over index.js: After all plugins loaded
    Caller->>index.js: ensureActiveApp()
    alt exactly 1 active app
        index.js-->>Caller: return (no-op)
    else multiple active apps
        index.js->>setActiveApp: setActiveApp(activeApps[0].id)
        setActiveApp->>SidebarApp: enforce single active
    else no active apps
        index.js->>setActiveApp: setActiveApp(apps[0].id)
        setActiveApp->>SidebarApp: activate first app
    end

    Note over index.js: User clicks sidebar icon
    Caller->>index.js: onclick(e)
    index.js->>setActiveApp: setActiveApp(id)
    setActiveApp->>SidebarApp: app.active = true (matched)
    setActiveApp->>SidebarApp: app.active = false (others)
    setActiveApp->>index.js: currentSection = id
    setActiveApp->>index.js: localStorage.setItem(...)
Loading

Last reviewed commit: 9b8d0d3

@bajrangCoder bajrangCoder merged commit d79a906 into Acode-Foundation:main Mar 9, 2026
6 checks passed
@bajrangCoder bajrangCoder deleted the fix/sidebar-app-activation branch March 9, 2026 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant