Overview

Remove the JS aggregation warning that https://git.drupalcode.org/project/experience_builder/-/merge_requests/1... added, and looks like this:

Proposed resolution

TBD

User interface changes

That warning is gone :)

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

wim leers created an issue. See original summary.

akhil babu’s picture

Assigned: Unassigned » akhil babu
wim leers’s picture

Thanks, @akhil babu! 😄

akhil babu’s picture

Assigned: akhil babu » Unassigned

Couldn't figure out why the widget is not working with js aggregation enabled :( Maybe something to do with the order in which the js is executed?

johnwebdev’s picture

So I think I understand why this is happening, but I'm not yet sure how to solve it:

In experience_builder/ui/src/services/processResponseAssets.ts we have:

    try {
      await Drupal.AjaxCommands.prototype['add_js'](
        {
          instanceIndex: Drupal.ajax.instances.length + 1,
          selector: 'head',
        },
        {
          command: 'add_js',
          status: 'success',
          data: js.filter(
            (item: JsAttachItem) =>
              item.src && !document.querySelector(`script[src="${item.src}"]`),
          ),
        },
      );
    } catch (e) {
      console.error(e);
    }
  }

The following line:

item.src && !document.querySelector(`script[src="${item.src}"]`),

makes sure we don't add a JavaScript file that's already been added. The problem is that when we have aggregation enabled the file name is random and will contain multiple libraries/files.

So what's happening here is that multiple JS files already loaded will be loaded incorrectly again, and e.g core/misc/ajax.js gets loaded twice, and I can see that it doesn't get the commands registered correctly (openDialog, closeDialog) from e.g dialog.ajax.

omkar-pd made their first commit to this issue’s fork.

omkar-pd’s picture

Assigned: Unassigned » omkar-pd
omkar-pd’s picture

StatusFileSize
new163.84 KB

If aggregation is on in console I see

processResponseAssets.ts:45 TypeError: Cannot read properties of undefined (reading 'prototype')
    at processResponseAssets (processResponseAssets.ts:36:33)
    at executeEndpoint (chunk-ROQIBUHR.js?v=6a6fe84e:757:37)
    at async chunk-4IJSOCZX.js?v=6a6fe84e:2594:27
    at async Promise.all (index 1)

upon logging Drupal we get- the ajax,AjaxCommands is not getting attached.
log

omkar-pd’s picture

Status: Active » Needs review

Turns out ajax, AjaxCommands are not getting attached because of this error

Uncaught 
TypeError: Cannot read properties of null (reading 'classList')
    at getRootMargin (js_rMknyV8zDbWnzkCOj…Lc0EAHp4CYM:28:1903)
    at monitorNavPosition (js_rMknyV8zDbWnzkCOj…Lc0EAHp4CYM:28:2247)
    at js_rMknyV8zDbWnzkCOj…Lc0EAHp4CYM:28:3024
    at js_rMknyV8zDbWnzkCOj…Lc0EAHp4CYM:28:3147

this error comes from core/themes/olivero/js/navigation-utils.js. I solved this error manually and media library widget works with aggregation on.

Moving this to needs review just to check If others getting same error in console.

omkar-pd’s picture

Assigned: omkar-pd » Unassigned
atul_ghate’s picture

StatusFileSize
new803.58 KB

I am also encountering the same issue when JavaScript aggregation is enabled.
xb

akhil babu’s picture

StatusFileSize
new2.82 MB

Hi @atul_ghate, Did you test with the latest changes?

I tested MR 277 and the media library widget works fine with JS aggregation enabled
/files/issues/2024-09-09/xb-media-library-widget.gif

Pushed one more commit to the MR to remove the warning

omkar-pd’s picture

@akhil babu,

Check the screenshot in IS, the media library widget should look like it.

Please test again with a fresh install.
1. Install Drupal
2. Enable Media, Media Library, XB, Xb Vite Integration modules,
3. Add article and go xb/node/1
4. Click on the image component & check the console for errors.
5. If you click on Add Media it does not work.

omkar-pd’s picture

Assigned: Unassigned » omkar-pd
omkar-pd’s picture

Status: Needs review » Needs work
omkar-pd’s picture

wim leers’s picture

Title: Make Media Library widget work when JS aggregation is enabled » [PP-1] Make Media Library widget work when JS aggregation is enabled
Status: Needs work » Postponed

I was going to say this too, I'm ~90% confident that #3472900: XBEndpointRenderer & processResponseAssets() do not support `ajaxPageState` ⇒ duplicate CSS/JS loading will fix this. See my detailed analysis at #3472900-13: XBEndpointRenderer & processResponseAssets() do not support `ajaxPageState` ⇒ duplicate CSS/JS loading for why.

(I haven't read this issue in detail, otherwise it'd probably be 99%.)

wim leers’s picture

Title: [PP-1] Make Media Library widget work when JS aggregation is enabled » Make Media Library widget work when JS aggregation is enabled
Status: Postponed » Needs review
Issue tags: +Needs manual testing, +Novice
wim leers’s picture

wim leers’s picture

Issue tags: +DrupalCon Barcelona 2024
bnjmnm’s picture

Version: » 0.x-dev

I believe #3472900: XBEndpointRenderer & processResponseAssets() do not support `ajaxPageState` ⇒ duplicate CSS/JS loading fully addresses this and has the e2e test as proof, but we should at least use this issue to remove the LOC in experience_builder_field_widget_complete_form_alter that are there only to report that the widget does not work with aggregation

if (isset($context['form']['#parents']) && array_search('xb_component_props', $context["form"]["#parents"]) !== FALSE) {
    RenderArrayXB::markXB($field_widget_complete_form);
    if ($context['widget']->getPluginId() === 'media_library_widget') {
      $config = \Drupal::service('config.factory')->getEditable('system.performance');
      $js_preprocess = $config->get('js.preprocess');
      if (!empty($js_preprocess)) {
        $field_widget_complete_form['#suffix'] = 'Warning: This site has JS aggregation enabled. The media library widget will not work unless it is disabled. This will, of course, be addressed soon.';
      }
    }
  }
wim leers’s picture

Title: Make Media Library widget work when JS aggregation is enabled » Remove obsolete message about Media Library widget not working when JS aggregation is enabled
Category: Bug report » Task
Priority: Critical » Normal
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs manual testing

#24 — whew, great call! 😅

wim leers’s picture

Assigned: Unassigned » bnjmnm
kristen pol’s picture

Issue tags: -DrupalCon Barcelona 2024 +Barcelona2024

Fixing tag

  • bnjmnm committed 7b693758 on 0.x authored by omkar-pd
    Issue #3471974 by omkar-pd, wim leers, bnjmnm: Remove obsolete message...
bnjmnm’s picture

Assigned: bnjmnm » Unassigned
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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