From 7b925ce94ac410c870334488ff2e8978a8bcfeaa Mon Sep 17 00:00:00 2001 From: Shubham Padia Date: Thu, 5 Jun 2025 08:08:01 +0000 Subject: [PATCH] buddy_list: Set html instead of append for view all subscribers link. Earlier, we were appending view all subscribers link using JQuery.append, which leaves open the possibility for the component to be appended multiple times if the function calling it gets called multiple times. It is better to have the link div in right_sidebar.hbs and then insert the html when required. --- web/src/buddy_list.ts | 12 +++++------- web/templates/buddy_list/view_all_subscribers.hbs | 12 +++++------- web/templates/right_sidebar.hbs | 1 + web/tests/lib/buddy_list.cjs | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/web/src/buddy_list.ts b/web/src/buddy_list.ts index 1b76cda59c..f9c3ecdb62 100644 --- a/web/src/buddy_list.ts +++ b/web/src/buddy_list.ts @@ -366,7 +366,7 @@ export class BuddyList extends BuddyListConf { this.fill_screen_with_content(); // This must happen after `fill_screen_with_content` - $("#buddy-list-users-matching-view-container .view-all-subscribers-link").remove(); + $("#buddy-list-users-matching-view-container .view-all-subscribers-link").empty(); $("#buddy-list-other-users-container .view-all-users-link").empty(); void this.render_view_user_list_links(); this.display_or_hide_sections(); @@ -746,12 +746,10 @@ export class BuddyList extends BuddyListConf { current_sub, "subscribers", ); - $("#buddy-list-users-matching-view-container").append( - $( - render_view_all_subscribers({ - stream_edit_hash, - }), - ), + $("#buddy-list-users-matching-view-container .view-all-subscribers-link").html( + render_view_all_subscribers({ + stream_edit_hash, + }), ); } diff --git a/web/templates/buddy_list/view_all_subscribers.hbs b/web/templates/buddy_list/view_all_subscribers.hbs index c8a5d62c19..4d5270341e 100644 --- a/web/templates/buddy_list/view_all_subscribers.hbs +++ b/web/templates/buddy_list/view_all_subscribers.hbs @@ -1,7 +1,5 @@ - + + + {{t "View all subscribers" }} + + diff --git a/web/templates/right_sidebar.hbs b/web/templates/right_sidebar.hbs index 0e6053ad7b..0b94a4bd6f 100644 --- a/web/templates/right_sidebar.hbs +++ b/web/templates/right_sidebar.hbs @@ -20,6 +20,7 @@
+
diff --git a/web/tests/lib/buddy_list.cjs b/web/tests/lib/buddy_list.cjs index a0c5e21199..13f8acbcc3 100644 --- a/web/tests/lib/buddy_list.cjs +++ b/web/tests/lib/buddy_list.cjs @@ -41,7 +41,7 @@ exports.stub_buddy_list_elements = () => { $("#buddy-list-users-matching-view .empty-list-message").length = 0; $("#buddy-list-other-users .empty-list-message").length = 0; $("#buddy-list-other-users-container .view-all-users-link").length = 0; - $("#buddy-list-users-matching-view-container .view-all-subscribers-link").remove = noop; + $("#buddy-list-users-matching-view-container .view-all-subscribers-link").empty = noop; $("#buddy-list-other-users-container .view-all-users-link").empty = noop; $(`#buddy-list-users-matching-view .empty-list-message`).remove = noop; $(`#buddy-list-other-users .empty-list-message`).remove = noop;