Overview

As I've been creating content with XB, I'm noticing that quite often the "Add media" button doesn't actually work after I have been interacting with XB (i.e. build content). After I refresh XB, the "Add media" button works again.

Steps to reproduce:

  1. Load XB with two components using image placed in the canvas
  2. Open component 1 and click "Add media"
  3. Close media library
  4. Open component 2 and click "Add media"
  5. Close media library
  6. Go back to component 1 and click "Add media"
  7. Notice, media library does not open

Proposed resolution

User interface changes

CommentFileSizeAuthor
media-library-not-opening.mp49.82 MBlauriii
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lauriii created an issue. See original summary.

sea2709 made their first commit to this issue’s fork.

bnjmnm’s picture

Status: Active » Postponed

The fix in #3490102: Add test for uploading new image in media library should fix this, but even if it doesn't it should be committed before any work proceeds on this as it addresses an underlying issue that causes all sorts of flakiness.

That issue has a fix and tests already. The final thing needed is to set up Gitlab CI so a built version of the UI app is available to FunctionalJavascript tests.

kristen pol’s picture

I'm running into this where I click the "add media" button and it briefly says "opening media library" but nothing happens and there are no console or dblog messages.

lauriii’s picture

Priority: Normal » Major
Status: Postponed » Active

It seems that this is consistently reproducible with https://github.com/phenaproxima/xb-demo.

kristen pol’s picture

Yeah... I didn't have the problem with latest XB and SDDS on vanilla D11.

bnjmnm’s picture

I installed the Drupal CMS demo and reproduced the issue has well
I also confirmed that disabling JS aggregation makes the issue go away, which helpfully narrows down what the underlying cause might be. Will investigate further.

kristen pol’s picture

Interesting. We had to leave aggregation off in the early days pre-Barcelona

bnjmnm’s picture

Interesting. We had to leave aggregation off in the early days pre-Barcelona

With that being mentioned I think it's important to share I've already found the underlying cause and it's a very different set of factors than what is mentioned above. MR on the way.

bnjmnm’s picture

Note that with Drupal CMS, the dialog buttons might not appear visible due to not having certain styles. This is unrelated to anything discussed here and requires patching Gin with this.

nagwani’s picture

Issue tags: +sprint
bnjmnm’s picture

Status: Active » Needs review

The Cause

Fairly recently, Experience Builder added several custom libraries that are largely identical to core libraries but with small differences to address things like CSS leakage or applying Admin theme overrides despite the XB UI not using the admin theme. We need to make them distinct libraries instead of instead of alter() ing them as the alters should only apply in XB contexts, something the library cache isn't easily aware of.

This approach works well, but it also results in multiple libraries potentially having the same assets. Drupal's AJAX system does an excellent job of preventing libraries from being added multiple times, but nothing to prevent assets from being re-added if they belong to a not-yet-added library. The specific problem reported was occurring because misc/ajax.js was being re-loaded.

There was already logic in Experience builder to prevent core libraries with existing XB equivalents from being directly added, but this was not being prevented if the library was a dependency. In this case, core/drupal.ajax was being re-added as a dependency of media_library/ui

The Solution

There might be something cleaner... but for now: drupalSettings now keeps track of all JS assets added by XB-specific libraries that load by default with the XB UI. processResponseAssets checks the list in drupalSettings and skips loading any JS already listed there - regardless of which library requested it.

To Review

This is hard to reproduce with a plain XB install, but the issue is immediately apparent in Drupal CMS when attempting to change the image in the card component.

Note that with Drupal CMS, the dialog buttons might not appear visible due to not having certain styles. This is unrelated to anything within the scope of this issue... it just happens to be in Media Library. Getting the buttons visible requires patching Gin with this, so it properly includes all the stylesheets necessary to display dialogs.

wim leers’s picture

I think a simpler/more elegant solution is possible, but it's still fundamentally the same solution, just solved on the server side instead.

wim leers’s picture

Assigned: Unassigned » bnjmnm
Status: Needs review » Needs work
bnjmnm’s picture

Status: Needs work » Needs review

Back to nr, see #13 for steps

bnjmnm’s picture

Assigned: bnjmnm » Unassigned
wim leers’s picture

Assigned: Unassigned » bnjmnm
Status: Needs review » Needs work

Wow, so much simpler!

A few questions on the MR, but this feels much closer to ready! 🤩

pameeela’s picture

With this patch, I'm able to open the media library in the Drupal CMS XB demo! But now I'm hitting the original issue in #3490102: Add test for uploading new image in media library where nothing happens when I upload. Is this unexpected?

bnjmnm’s picture

Assigned: bnjmnm » Unassigned
Status: Needs work » Needs review
gábor hojtsy’s picture

wim leers’s picture

Component: Page builder » Redux-integrated field widgets
Assigned: Unassigned » jessebaker
Status: Needs review » Reviewed & tested by the community
bnjmnm’s picture

Status: Reviewed & tested by the community » Needs work

Current solution is able to prevent the duplicate loading of assets by AJAX requests made by the UI app, but does not prevent the duplicate loading of assets if the duplication prone library requests comes from elsewhere, which is what I'm running into manually atm.

bnjmnm’s picture

Status: Needs work » Needs review
bnjmnm’s picture

Assigned: jessebaker » Unassigned

Remove the test skipping stuff so anyone can review now.

bnjmnm’s picture

Assigned: Unassigned » wim leers

Assigning to Wim since they provided the initial RTBC, so it should only require looking at the changes since then.

  • bnjmnm committed c672b2fe on 0.x
    Issue #3491047 by bnjmnm, wim leers, sea2709: "Add media" button doesn't...
bnjmnm’s picture

Assigned: wim leers » Unassigned
Status: Needs review » Fixed

I was the un-rtbc'r and since then a few approvals happened. Given that this is also soft blocking some other issues I'm gonna bring it in.

wim leers’s picture

effulgentsia’s picture

Title: "Add media" button doesn't always open the media library » [Needs followup] "Add media" button doesn't always open the media library
Issue tags: -sprint
bnjmnm’s picture

Assigned: bnjmnm » Unassigned
Status: Needs work » Fixed
Related issues: +#3537647: Nit followups to #3491047

Status: Fixed » Closed (fixed)

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