Media Library modal opens randomly on AJAX requests

Created on 1 October 2020, over 4 years ago
Updated 24 May 2023, almost 2 years ago

Problem/Motivation

When triggering two AJAX requests subsequently on a node edit / add page and making sure you trigger the last one before the first one can finish, the Media Library modal will open up. This only seem to happen if there is another Media field in the page. I reproduce this with the Paragraphs module, though I'm not certain if that module has a specific role in this bug, I'm having the feeling it will trigger in any AJAX action.

This bug get's real tedious in some specific production environments, where we've encountered node setups where there are file fields that need to be filled and people will add them too quickly also triggering this bug. At this specific event, they weren't even able to click any more buttons, forcing them to hard reload the page and lose their progress.

Steps to reproduce

  1. Install Drupal (I used 8.9.2 in this reproduction case) with the standard installation profile
  2. Install Media and Media Library modules
  3. Download and install the Paragraphs module
  4. Setup a Media field in the Page node, default settings
  5. Setup a simple paragraph type with for example a text field
  6. Setup a paragraph reference field in the Page node
  7. Go to the node add page for Page
  8. Add two additional paragraphs for a total of minimal 3
  9. Try to delete the two added paragraphs, making sure you click the "Remove" button before the throttler of the first one is finished
  10. Note that the "Add or select media" dialog opens

Also see the screen recording I added for a more visual explanation.

Proposed resolution

Fix it

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Media 

Last updated 35 minutes ago

Created by

🇳🇱Netherlands aken.niels@gmail.com

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇫🇮Finland heikkiy Oulu

    We have been struggling and debugging this issue for a couple months also. We have two different paragraph fields in the node edit form and it seems to behave exactly the same as described in the comments in this issue.

    It seems like it is the combination of Paragraphs and Entity browser which results in the bug because in another project we have a similar setup but without Entity browser and we haven't encountered the same issue there. We can test if we can reproduce the issue with Paragraphs and core Media Library.

    Sending the Ajax call seems to return the wrong element it replaces the wrong paragraph after the element is added. I originally reported the issue to Paragraphs module https://www.drupal.org/project/paragraphs/issues/3356796 🐛 Multiple paragraph fields in a single content type can cause conflicting behavior in frontend Active and there is also a video recording of the effect.

  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇬🇧United Kingdom andyrigby

    We've just experienced this issue, but it was reproducible each time on a particular Paragraph "Remove" button.

    The node edit form was large; lots of paragraphs, fields, meta tags, schema.org metatags etc.

    The issue was the _triggering_element_name was not present in the POST variables, even though it was sent by the browser.

    We needed to increase the max_input_vars php setting from 1000 to 1200 (in our case)

    This resolved it for us.

  • 🇫🇮Finland heikkiy Oulu

    I checked our PHP settings to check the solution from #25. In our case max_input_vars is already set to 5000 but we are still experiencing the original issue. It is of course possible that our paragraph and node forms with multiple tabs are so large that even 5000 is not enough to hold the original variable.

    @andyrigby could you give more detailed instructions how you tested that the _triggering_element_name is not present in the POST variables? I could try playing around with our test environment to see if I can reproduce the problem with our current settings and if raising the limit would help.

  • 🇫🇮Finland heikkiy Oulu

    We tested increasing the max_input_vars to 10 000 but were still able to reproduce the issue. In our case it happens that if you are too quickly opening and closing a media modal it gets replaced by a paragraph element. It seems like the reason is that the previous modal request isn't completed when the next one starts so it seems like a race condition. It took us approximately 4-5 clicks of opening and closing the modal to get the wrong form displayed.

  • 🇧🇪Belgium ludo.r Brussels

    We're experiencing this issue also on Drupal 10.2.8.
    Seems also that when this happens, content is lost upon save.

    I think this should be major issue.

  • 🇺🇸United States bkosborne New Jersey, USA

    I added 🐛 Form cache causes issues with media library widget Active which I think might be related to this.

Production build 0.71.5 2024