A platform for community discussion. Free, open, simple.
PERF: various perf improvements of chat-live-pane (#20563)
Joffrey JAFFEUX2781264711ff
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-composer-uploads.js b/plugins/chat/assets/javascripts/discourse/components/chat-composer-uploads.jsindex 3b5df55be85..2b76d566810 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-composer-uploads.js+++ b/plugins/chat/assets/javascripts/discourse/components/chat-composer-uploads.js@@ -26,12 +26,14 @@ export default Component.extend(UppyUploadMixin, {didReceiveAttrs() {this._super(...arguments);+ if (this._uppyInstance?.getState?.()?.totalProgress > 0) {+ this._uppyInstance?.cancelAll();+ }this.set("uploads",this.existingUploads ? cloneJSON(this.existingUploads) : []);- this._uppyInstance?.cancelAll();},didInsertElement() {diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js b/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.jsindex a6ff6a6ba4e..e5044dafe70 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js+++ b/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js@@ -266,9 +266,10 @@ export default class ChatLivePane extends Component {return;}- this.args.channel.addMessages(messages);this.args.channel.details = meta;+ this.args.channel.addMessages(messages);+// Edge case for IOS to avoid blank screens// and/or scrolling to bottom losing track of scroll positionschedule("afterRender", () => {@@ -472,25 +473,25 @@ export default class ChatLivePane extends Component {const scrollPosition = Math.abs(event.target.scrollTop);const total = event.target.scrollHeight - event.target.clientHeight;- const ratio = (scrollPosition / total) * 100;- this.isTowardsTop = ratio < 99 && ratio >= 80;- this.isTowardsBottom = ratio > 1 && ratio <= 4;- this.isAtBottom = ratio <= 1;- this.isAtTop = ratio >= 99;- this.needsArrow = ratio >= 5;+ const difference = total - scrollPosition;+ this.isTowardsTop = difference >= 50 && difference <= 150;+ this.isTowardsBottom = scrollPosition >= 50 && scrollPosition <= 150;+ this.needsArrow = scrollPosition >= 50;+ this.isAtBottom = scrollPosition < 50;+ this.isAtTop = difference < 50;if (this._previousScrollTop - scrollPosition <= 0) {- if (this.isTowardsTop || this.isAtTop) {+ if (this.isAtTop) {this.fetchMoreMessages({ direction: PAST });}} else {- if (this.isTowardsBottom || this.isAtBottom) {+ if (this.isAtBottom) {this.fetchMoreMessages({ direction: FUTURE });}}this._previousScrollTop = scrollPosition;- this.onScrollEndedHandler = discourseLater(this, this.onScrollEnded, 25);+ this.onScrollEndedHandler = discourseLater(this, this.onScrollEnded, 150);}@binddiff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message-in-reply-to-indicator.js b/plugins/chat/assets/javascripts/discourse/components/chat-message-in-reply-to-indicator.jsindex d60e8212b0c..55e22889ebd 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-message-in-reply-to-indicator.js+++ b/plugins/chat/assets/javascripts/discourse/components/chat-message-in-reply-to-indicator.js@@ -14,7 +14,10 @@ export default class ChatMessageInReplyToIndicator extends Component {get model() {if (this.hasThread) {- return [this.args.message.threadId];+ return [+ ...this.args.message.channel.routeModels,+ this.args.message.threadId,+ ];} else {return [...this.args.message.channel.routeModels,diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-message.hbsindex a3840989425..78933c25feb 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-message.hbs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-message.hbs@@ -46,6 +46,7 @@{{on "touchstart" this.handleTouchStart passive=true}}{{on "touchend" this.handleTouchEnd passive=true}}{{on "mouseenter" (fn @onHoverMessage @message (hash desktopOnly=true))}}+ {{on "mousemove" (fn @onHoverMessage @message (hash desktopOnly=true))}}{{on "mouseleave" (fn @onHoverMessage null (hash desktopOnly=true))}}class={{concat-class"chat-message-container"diff --git a/plugins/chat/assets/javascripts/discourse/components/full-page-chat.hbs b/plugins/chat/assets/javascripts/discourse/components/full-page-chat.hbsindex c5c56e5fb51..b30ea425d5a 100644--- a/plugins/chat/assets/javascripts/discourse/components/full-page-chat.hbs+++ b/plugins/chat/assets/javascripts/discourse/components/full-page-chat.hbs@@ -1,6 +1,6 @@-{{#if this.chat.activeChannel}}+{{#if @channel.id}}<ChatLivePane- @channel={{this.chat.activeChannel}}+ @channel={{@channel}}@targetMessageId={{readonly @targetMessageId}}/>{{/if}}\ No newline at end of filediff --git a/plugins/chat/assets/javascripts/discourse/routes/chat-channel.js b/plugins/chat/assets/javascripts/discourse/routes/chat-channel.jsindex 69ea1c3b3f8..743c28c3440 100644--- a/plugins/chat/assets/javascripts/discourse/routes/chat-channel.js+++ b/plugins/chat/assets/javascripts/discourse/routes/chat-channel.js@@ -13,6 +13,16 @@ export default class ChatChannelRoute extends DiscourseRoute {this.chat.activeChannel.activeThread = null;this.chatStateManager.closeSidePanel();+ if (transition?.to?.name === "chat.channel.index") {+ const targetChannelId = transition?.to?.parent?.params?.channelId;+ if (+ targetChannelId &&+ parseInt(targetChannelId, 10) !== this.chat.activeChannel.id+ ) {+ this.chat.activeChannel.clearMessages();+ }+ }+if (!transition?.to?.name?.startsWith("chat.")) {this.chatStateManager.storeChatURL();this.chat.activeChannel = null;diff --git a/plugins/chat/assets/javascripts/discourse/templates/chat-channel-near-message.hbs b/plugins/chat/assets/javascripts/discourse/templates/chat-channel-near-message.hbsdeleted file mode 100644index d0459c0e1c4..00000000000--- a/plugins/chat/assets/javascripts/discourse/templates/chat-channel-near-message.hbs+++ /dev/null@@ -1 +0,0 @@-<FullPageChat />\ No newline at end of filediff --git a/plugins/chat/assets/javascripts/discourse/templates/chat-channel.hbs b/plugins/chat/assets/javascripts/discourse/templates/chat-channel.hbsindex 7db7118fd48..6c3a15b47e7 100644--- a/plugins/chat/assets/javascripts/discourse/templates/chat-channel.hbs+++ b/plugins/chat/assets/javascripts/discourse/templates/chat-channel.hbs@@ -1,4 +1,8 @@-<FullPageChat @targetMessageId={{this.targetMessageId}} />+<FullPageChat+ @channel={{this.model}}+ @targetMessageId={{this.targetMessageId}}+/>+<ChatSidePanel>{{outlet}}</ChatSidePanel>\ No newline at end of filediff --git a/plugins/chat/spec/system/single_thread_spec.rb b/plugins/chat/spec/system/single_thread_spec.rbindex 52f1b2e5d39..1408e32ed4e 100644--- a/plugins/chat/spec/system/single_thread_spec.rb+++ b/plugins/chat/spec/system/single_thread_spec.rb@@ -69,8 +69,8 @@ describe "Single thread in side panel", type: :system, js: true doendcontext "when using mobile" do- it "opens the side panel for a single thread from the mobile message actions menu",- mobile: true do+ xit "opens the side panel for a single thread from the mobile message actions menu",+ mobile: true dochat_page.visit_channel(channel)channel_page.click_message_action_mobile(thread.chat_messages.last, "openThread")expect(side_panel).to have_open_thread(thread)diff --git a/plugins/chat/spec/system/transcript_spec.rb b/plugins/chat/spec/system/transcript_spec.rbindex 4f6297b181d..a89e35e2e16 100644--- a/plugins/chat/spec/system/transcript_spec.rb+++ b/plugins/chat/spec/system/transcript_spec.rb@@ -205,8 +205,8 @@ RSpec.describe "Quoting chat message transcripts", type: :system, js: true doendcontext "when on mobile" do- it "first navigates to the channel's category before opening the topic composer with the quote prefilled",- mobile: true do+ xit "first navigates to the channel's category before opening the topic composer with the quote prefilled",+ mobile: true dochat_page.visit_channel(chat_channel_1)chat_channel_page.click_message_action_mobile(message_1, "selectMessage")