Use once to avoid attaching behavior multiple times

Created on 25 October 2023, about 1 year ago
Updated 5 September 2024, 3 months ago

Problem/Motivation

The current code at `/js/disclaimer.js` is attaching multiple times on the page. This is annoying when there are ajax calls as it will cause the page to scroll to the top of the page due to this code:

            if (gadget) {
              // Focus on the link. I don't know why we need delay but something
              // keeps the focus from happening without it.
              window.setTimeout(() => gadget.focus(), 500);

              // Found the gadget, end the MutationObserver.
              obs.disconnect();
              return;
            }

Steps to reproduce

Several ways to reproduce, easiest one is create a view that use ajax filters. Set it in a way that you can scroll a lot. After applying filters, confirm that you are taken to the translate block.

Proposed resolution

Use once https://www.drupal.org/node/3158256 β†’

πŸ› Bug report
Status

Needs review

Version

2.1

Component

Code

Created by

πŸ‡¨πŸ‡·Costa Rica alemadlei

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @alemadlei
  • Status changed to Postponed: needs info 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States jenna.tollerson Atlanta, Georgia, USA

    Hi there, thank you for your report. I am having trouble reproducing this bug.

    1. I created a view page display with an exposed filter and checked "Use AJAX" under the advanced options.
    2. With the Translator block placed near the top of the page, I clicked on the text to show the Google widget, accepted the disclaimer, and chose a language.
    3. With the page translated, I scrolled down so the translator block was out of view.
    4. I made a new selection on the exposed filter and applied it.
    5. I was not taken back to the top of the page. The filtered content loaded as expected.

    Can you still reproduce this issue in the 2.x branch?

  • πŸ‡ΊπŸ‡ΈUnited States j-barnes

    @jenny.tollerson / @alemadlei - Our team was running into the same issue using the "Views Infinite Scroll" pager in a view with ajax enabled. After the user clicks the "Load More" it jump back up to the top of the page after a minor delay. We have the translate block attached to the top of the page via block layout. Adding this has cured the problem for us, thanks for the patch!

  • Status changed to Needs review 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States j-barnes
  • πŸ‡ΊπŸ‡ΈUnited States mherchel Gainesville, FL, US

    I'm experiencing this issue as well.

    @jenna.tollerson note that that this is more likely to occur when you're logged in, as Drupal will be running attachBehaviors more.

    The MR fixes the issue for me and seems to be great. Attaching the patch here so I can reference it via composer patches.

  • Pipeline finished with Skipped
    about 2 months ago
    #311028
  • πŸ‡ΊπŸ‡ΈUnited States jenna.tollerson Atlanta, Georgia, USA

    Thanks all, good enough for me.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024