Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

buddy_list: Don't update UI after await calls when view has changed.

Evy Kassirerc3ce273c4b48
diff --git a/web/src/buddy_list.ts b/web/src/buddy_list.ts
index ae295fa65af..b87d0548ea2 100644
--- a/web/src/buddy_list.ts
+++ b/web/src/buddy_list.ts
@@ -408,12 +408,19 @@ export class BuddyList extends BuddyListConf {
return;
}
- const {get_all_participant_ids} = this.render_data;
+ const {current_sub, get_all_participant_ids} = this.render_data;
$("#buddy-list-users-matching-view .empty-list-message").remove();
if ((await this.non_participant_users_matching_view_count()) > 0) {
// There are more subscribers, so we don't need an empty list message.
return;
- } else if (get_all_participant_ids().size > 0) {
+ }
+ // After the `await`, we might have changed to a different channel view.
+ // If so, we shouldn't update the DOM anymore, and should let the newer `populate`
+ // call set things up with fresh data.
+ if (current_sub !== this.render_data.current_sub) {
+ return;
+ }
+ if (get_all_participant_ids().size > 0) {
add_or_update_empty_list_placeholder(
"#buddy-list-users-matching-view",
$t({defaultMessage: "No other subscribers."}),
@@ -445,6 +452,13 @@ export class BuddyList extends BuddyListConf {
);
const formatted_other_users_count = get_formatted_user_count(other_users_count);
+ // After the `await`, we might have changed to a different channel view.
+ // If so, we shouldn't update the DOM anymore, and should let the newer `populate`
+ // call set things up with fresh data.
+ if (current_sub !== this.render_data.current_sub) {
+ return;
+ }
+
$("#buddy-list-participants-container .buddy-list-heading-user-count").text(
formatted_participants_count,
);
@@ -680,6 +694,13 @@ export class BuddyList extends BuddyListConf {
this.users_matching_view_ids.length;
const has_inactive_other_users = other_users_count > this.other_user_ids.length;
+ // After the `await`, we might have changed to a different channel view.
+ // If so, we shouldn't update the DOM anymore, and should let the newer `populate`
+ // call set things up with fresh data.
+ if (current_sub !== this.render_data.current_sub) {
+ return;
+ }
+
// For stream views, we show a link at the bottom of the list of subscribed users that
// lets a user find the full list of subscribed users and information about them.
if (