From d14456ac7eea1f161c27fffeafa6098442299761 Mon Sep 17 00:00:00 2001 From: Noah Bravo Date: Fri, 1 May 2026 23:05:20 +0200 Subject: [PATCH 1/2] AO3-5047 Prevent duplicate AJAX flash messages --- app/views/users/show.html.erb | 2 +- features/tags_and_wrangling/favorite_tags.feature | 15 +++++++++++++++ public/javascripts/application.js | 7 ++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 6d33b9d7fd1..cb9c756e883 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,6 +1,6 @@ <% if @user == current_user && @user.preference.try(:first_login) %> -
+

<%= t(".login_banner.welcome_html", new_user_tips_link: link_to_modal(t(".login_banner.new_user_tips"), for: help_first_login_path, title: t(".login_banner.help_title")), diff --git a/features/tags_and_wrangling/favorite_tags.feature b/features/tags_and_wrangling/favorite_tags.feature index 49267341ebb..a74a75d3087 100644 --- a/features/tags_and_wrangling/favorite_tags.feature +++ b/features/tags_and_wrangling/favorite_tags.feature @@ -37,3 +37,18 @@ Feature: Favorite Tags When the tag "Rebecca Sutter" is decanonized And I go to the homepage Then I should not see "Rebecca Sutter" + + @javascript + Scenario: Favoriting a tag only shows one AJAX notice when another flash is already present + Given a canonical fandom "Dallas (TV 2012)" + And the user "bourbon" exists and is activated + And I am a visitor + When I view the "Dallas (TV 2012)" works index + And I follow "Log In" within "#header" + And I fill in "user_session_login_small" with "bourbon" within "#login" + And I fill in "user_session_password_small" with "password" within "#login" + And I press "Log In" within "#login" + Then I should see "Successfully logged in" + And I should see a "Favorite Tag" button + When I press "Favorite Tag" + Then I should see "You have successfully added Dallas (TV 2012) to your favorite tags." exactly 1 time diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 6962ec7f567..82f28197fe1 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -461,6 +461,8 @@ $j(document).ready(function() { // data-destroy-value: text of button for destroying, e.g. Unfavorite, Unsubscribe // controller needs item_id and item_success_message for save success and // item_success_message for destroy success +// Limit AJAX flash messages to #main > .flash so they don't get duplicated +// when other flash-like banners are present $j(document).ready(function() { $j('form.ajax-create-destroy').on("click", function(event) { event.preventDefault(); @@ -470,7 +472,10 @@ $j(document).ready(function() { var formSubmit = form.find('[type="submit"]'); var createValue = form.data('create-value'); var destroyValue = form.data('destroy-value'); - var flashContainer = $j('.flash'); + var flashContainer = $j('#main > .flash').first(); + if (flashContainer.length === 0) { + return; + } $j.ajax({ type: 'POST', From 105f276c605e1666d89a2b1d44af2c7fd579ca1a Mon Sep 17 00:00:00 2001 From: Noah Bravo Date: Thu, 21 May 2026 11:46:51 +0200 Subject: [PATCH 2/2] AO3-5047 Follow review cleanup for banner and feature steps --- app/views/users/show.html.erb | 1 - features/tags_and_wrangling/favorite_tags.feature | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index cb9c756e883..b93cbfbba4c 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,5 +1,4 @@ <% if @user == current_user && @user.preference.try(:first_login) %> -

<%= t(".login_banner.welcome_html", diff --git a/features/tags_and_wrangling/favorite_tags.feature b/features/tags_and_wrangling/favorite_tags.feature index a74a75d3087..9337f0908a8 100644 --- a/features/tags_and_wrangling/favorite_tags.feature +++ b/features/tags_and_wrangling/favorite_tags.feature @@ -45,8 +45,8 @@ Feature: Favorite Tags And I am a visitor When I view the "Dallas (TV 2012)" works index And I follow "Log In" within "#header" - And I fill in "user_session_login_small" with "bourbon" within "#login" - And I fill in "user_session_password_small" with "password" within "#login" + And I fill in "Username or email:" with "bourbon" within "#login" + And I fill in "Password:" with "password" within "#login" And I press "Log In" within "#login" Then I should see "Successfully logged in" And I should see a "Favorite Tag" button