From 4c810703c15c60d3ee9da4faa75c82ab2599d13d Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Thu, 6 Jul 2023 10:53:28 +0800 Subject: [PATCH] FIX: Avoid transitioning when a chat thread component is destroyed (#22457) Why this change? Before this commit, there is a chance that we will transition the user to a different route if the chat thread component has been destroyed prior to the request for fetching messasges in a chat thread returning. This commit makes it such that we simply ignore the request if the chat thread component has been destroyed. We believe this is the cause of the flaky system tests in plugins/chat/spec/system/navigation_spec.rb which we've been seeing on CI. --- .../javascripts/discourse/components/chat-thread.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-thread.js b/plugins/chat/assets/javascripts/discourse/components/chat-thread.js index 7184f3664ba..bec16e7b756 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-thread.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat-thread.js @@ -166,10 +166,11 @@ export default class ChatThreadPanel extends Component { return this.chatApi .channel(this.args.thread.channel.id, findArgs) .then((result) => { - if ( - this._selfDeleted || - this.args.thread.channel.id !== result.meta.channel_id - ) { + if (this._selfDeleted) { + return; + } + + if (this.args.thread.channel.id !== result.meta.channel_id) { if (this.chatHistory.previousRoute?.name === "chat.channel.index") { this.router.transitionTo( "chat.channel",