Skip to content

AO3-5047 Prevent duplicate AJAX flash messages#5777

Open
noahbravo wants to merge 1 commit intootwcode:masterfrom
noahbravo:AO3-5047-ajax-flash-dedup
Open

AO3-5047 Prevent duplicate AJAX flash messages#5777
noahbravo wants to merge 1 commit intootwcode:masterfrom
noahbravo:AO3-5047-ajax-flash-dedup

Conversation

@noahbravo
Copy link
Copy Markdown
Contributor

Pull Request Checklist

Issue

https://otwarchive.atlassian.net/browse/AO3-5047

Purpose

Fixes duplicated flash messages for AJAX create/destroy actions (e.g. Favorite Tag) when another flash message/banner is already present on the page.

Root cause:

  • The ajax-create-destroy handler used a broad selector (.flash), causing messages to be written into multiple flash containers.

Changes made:

  • Scoped AJAX flash output to the main flash container only (#main > .flash) in public/javascripts/application.js.
  • Added a guard clause to skip flash rendering if no main flash container is found.
  • Updated the first-login help banner in app/views/users/show.html.erb from class="flash notice" to class="notice" so it is not treated as a flash target.

This keeps the fix minimal and aligned with the issue note about the first-login banner being a notice rather than a flash.

Testing Instructions

Follow Example 1 from AO3-5047:
https://otwarchive.atlassian.net/browse/AO3-5047

Expected behavior:

  • After logging in from a tag works index page and pressing Favorite Tag (or Unfavorite Tag), the success message appears only once.
  • The AJAX message should not duplicate into multiple blue banners.

Automated tests:

  • Added a new @javascript regression scenario in features/tags_and_wrangling/favorite_tags.feature covering:
    • logged-out user on tag works index
    • login from header form (existing "Successfully logged in" flash present)
    • Favorite Tag action
    • assertion that the success message appears exactly 1 time

Commands run:

  • docker compose run --rm test bundle exec cucumber features/tags_and_wrangling/favorite_tags.feature:42
  • docker compose run --rm test bundle exec cucumber features/tags_and_wrangling/favorite_tags.feature

Additional manual spot-check:

  • Tag page deep pagination case from Jira notes (e.g. high page number) should also show the AJAX success message only once.

Credit

Name: Noah Bravo
Pronouns: they/them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant