Skip to content

A platform for community discussion. Free, open, simple.

FIX: Clear forced sidebar when leaving AI Bot from another panel (#37455)

Keegan George8506eab38f23
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js b/plugins/discourse-ai/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js
index 0bc7b25c617..78c9a03f895 100644
--- a/plugins/discourse-ai/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js
+++ b/plugins/discourse-ai/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js
@@ -159,12 +159,16 @@ export default class AiConversationsSidebarManager extends Service {
document.body.classList.remove("has-ai-conversations-sidebar");
document.body.classList.remove("has-empty-ai-conversations-sidebar");
- // Only reset if no other route has claimed the sidebar in its activate() hook
+ // Only reset panel if no other route has claimed the sidebar in its activate() hook
const isStillAiPanel =
this.sidebarState.currentPanel?.key === AI_CONVERSATIONS_PANEL;
if (this.sidebarState.isForcingSidebar && isStillAiPanel) {
this.sidebarState.setPanel(MAIN_PANEL);
+ }
+
+ // Always clear the forcing flag when leaving AI conversations
+ if (this.sidebarState.isForcingSidebar) {
this.sidebarState.isForcingSidebar = false;
this.appEvents.trigger("discourse-ai:stop-forcing-conversations-sidebar");
}
diff --git a/plugins/discourse-ai/spec/system/ai_bot/ai_bot_sidebar_navigation_spec.rb b/plugins/discourse-ai/spec/system/ai_bot/ai_bot_sidebar_navigation_spec.rb
index c06356d463c..c11fa080aec 100644
--- a/plugins/discourse-ai/spec/system/ai_bot/ai_bot_sidebar_navigation_spec.rb
+++ b/plugins/discourse-ai/spec/system/ai_bot/ai_bot_sidebar_navigation_spec.rb
@@ -41,4 +41,26 @@ RSpec.describe "AI Bot sidebar navigation" do
expect(page).to have_no_css(".sidebar-sections.ai-conversations-panel")
expect(page).to have_no_css(".sidebar-sections.chat-panel")
end
+
+ context "with header dropdown navigation menu" do
+ before { SiteSetting.navigation_menu = "header dropdown" }
+
+ it "clears forced sidebar when navigating from AI bot to chat and then away" do
+ chat_page.prefers_full_page
+
+ ai_pm_homepage.visit
+
+ expect(page).to have_css(".sidebar-sections.ai-conversations-panel")
+
+ find(".chat-header-icon").click
+
+ expect(page).to have_css(".channels-list")
+ expect(page).to have_no_css("#sidebar-section-content-categories")
+
+ find("#site-logo").click
+
+ expect(page).to have_no_css(".sidebar-sections")
+ expect(page).to have_no_css(".channels-list")
+ end
+ end
end