A platform for community discussion. Free, open, simple.
FIX: messages list shouldn't scroll on new message (#26438)
Joffrey JAFFEUX453bf3acb3e6
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjsindex b76d932f470..ae604216918 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs@@ -74,7 +74,7 @@ export default class ChatChannel extends Component {@tracked showChatQuoteSuccess = false;@tracked includeHeader = true;@tracked needsArrow = false;- @tracked atBottom = false;+ @tracked atBottom = true;@tracked uploadDropZone;@tracked isScrolling = false;@@ -173,6 +173,12 @@ export default class ChatChannel extends Component {@bindonNewMessage(message) {+ if (!this.atBottom) {+ this.needsArrow = true;+ this.messagesLoader.canLoadMoreFuture = true;+ return;+ }+stackingContextFix(this.scrollable, () => {this.messagesManager.addMessages([message]);});diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjsindex ee9df33f77b..622ce76ea49 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs@@ -53,7 +53,7 @@ export default class ChatThread extends Component {@service router;@service siteSettings;- @tracked isAtBottom = true;+ @tracked atBottom = true;@tracked isScrolling = false;@tracked needsArrow = false;@tracked uploadDropZone;@@ -316,7 +316,15 @@ export default class ChatThread extends Component {@bindonNewMessage(message) {- this.messagesManager.addMessages([message]);+ if (!this.atBottom) {+ this.needsArrow = true;+ this.messagesLoader.canLoadMoreFuture = true;+ return;+ }++ stackingContextFix(this.scrollable, () => {+ this.messagesManager.addMessages([message]);+ });}@binddiff --git a/plugins/chat/spec/system/chat_channel_spec.rb b/plugins/chat/spec/system/chat_channel_spec.rbindex ba19c13a6c8..79e2cd016f7 100644--- a/plugins/chat/spec/system/chat_channel_spec.rb+++ b/plugins/chat/spec/system/chat_channel_spec.rb@@ -164,12 +164,12 @@ RSpec.describe "Chat channel", type: :system do50.times { Fabricate(:chat_message, chat_channel: channel_1) }end- xit "doesn’t scroll the pane" do+ it "doesn’t append the message when not at bottom" dovisit("/chat/c/-/#{channel_1.id}/#{message_1.id}")- new_message = Fabricate(:chat_message, chat_channel: channel_1)+ new_message = Fabricate(:chat_message, chat_channel: channel_1, use_service: true)- expect(page).to have_no_content(new_message.message)+ expect(channel_page.messages).to have_no_message(id: new_message.id)endend