Skip to content

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

FIX: Chat button respects drawer preference after page refresh

Jake Goldsborough43df251def9f
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/header/icon.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/header/icon.gjs
index 9bf78b00f88..ccb7178764a 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat/header/icon.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat/header/icon.gjs
@@ -1,4 +1,5 @@
import Component from "@glimmer/component";
+import { action } from "@ember/object";
import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
import concatClass from "discourse/helpers/concat-class";
@@ -13,6 +14,7 @@ export default class ChatHeaderIcon extends Component {
@service currentUser;
@service site;
@service chatStateManager;
+ @service router;
get showUnreadIndicator() {
if (this.chatStateManager.isFullPageActive && this.site.desktopView) {
@@ -61,25 +63,41 @@ export default class ChatHeaderIcon extends Component {
return "d-chat";
}
- get href() {
+ get targetUrl() {
if (
this.chatStateManager.isFullPageActive &&
!this.chatSeparateSidebarMode.never
) {
- return getURL(this.chatStateManager.lastKnownAppURL || "/");
+ return this.chatStateManager.lastKnownAppURL || "/";
}
if (this.chatStateManager.isDrawerActive) {
- return getURL("/chat");
+ return "/chat";
}
- return getURL(this.chatStateManager.lastKnownChatURL || "/chat");
+ return this.chatStateManager.lastKnownChatURL || "/chat";
+ }
+
+ get href() {
+ return getURL(this.targetUrl);
+ }
+
+ @action
+ openChat() {
+ // Opening chat: explicitly set drawer preference before navigating
+ // This ensures the route's beforeModel respects drawer mode even on
+ // full page loads (e.g., after browser refresh)
+ if (this.chatStateManager.isDrawerPreferred) {
+ this.chatStateManager.prefersDrawer();
+ }
+ this.router.transitionTo(this.targetUrl);
}
<template>
{{#unless (and this.site.mobileView this.isActive)}}
<li class="header-dropdown-toggle chat-header-icon">
<DButton
+ @action={{this.openChat}}
@href={{this.href}}
tabindex="0"
class={{concatClass "icon" "btn-flat" (if this.isActive "active")}}
diff --git a/plugins/chat/spec/system/drawer_spec.rb b/plugins/chat/spec/system/drawer_spec.rb
index 505579531ce..1bb8de695f8 100644
--- a/plugins/chat/spec/system/drawer_spec.rb
+++ b/plugins/chat/spec/system/drawer_spec.rb
@@ -29,6 +29,21 @@ RSpec.describe "Drawer", type: :system do
expect(page).to have_no_css("html.has-drawer-chat")
end
+ it "respects drawer preference after page refresh" do
+ visit("/")
+ chat_page.open_from_header
+ expect(page).to have_css("body.has-drawer-chat")
+
+ drawer_page.close
+ expect(page).to have_no_css("body.chat-drawer-active")
+
+ refresh
+
+ chat_page.open_from_header
+ expect(page).to have_css("body.has-drawer-chat")
+ expect(page).to have_no_css("body.has-full-page-chat")
+ end
+
context "when on channel" do
fab!(:channel, :chat_channel)
fab!(:membership) do