JS Aggregation breaks in 10.1 when disabling other javascripts

Created on 5 January 2024, 12 months ago

Problem/Motivation

On a Drupal 10.1 site, when this module is enabled, and also including javascripts to disable on the settings page, such as

modules/contrib/google_tag/js/gtag.js
modules/contrib/google_tag/js/gtm.js
modules/contrib/google_tag/js/gtag.ajax.js

And with Core JS aggregation enabled, JS aggregation breaks, breaking page functionality such as admin toolbar, etc..

For us, this only seems to happen on admin pages displaying in the Claro theme

Error appears in dblog

Symfony\Component\HttpKernel\Exception\BadRequestHttpException: Invalid filename. in Drupal\system\Controller\AssetControllerBase->getGroup() (line 224 of ./web/core/modules/system/src/Controller/AssetControllerBase.php).

Removing scripts from the "Disable the following JavaScripts when consent isn't given" "Disable Scripts" field makes JS aggregation work.

πŸ› Bug report
Status

Active

Version

1.24

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States markusa

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

Merge Requests

Comments & Activities

  • Issue created by @markusa
  • πŸ‡ΊπŸ‡ΈUnited States markusa

    When I "View Source" of admin vs. front end pages ..
    On admin pages:
    I see an aggregated js file, then 2 gtm js scripts NOT aggregated and then a couple more aggregated JS files
    On the front end, I don't see the un-aggregated gtm scripts in the source.

    So whatever its doing, when the gtm scripts are NOT in the aggregated scripts, the condition occurs.

    If I configure the Google Tag module to exclude /admin/* pages, the condition disappears.

    What bothers is why on the admin theme only, is there some 3rd component interacting?

  • πŸ‡ΊπŸ‡ΈUnited States kevinquillen

    This only appears to work if you Exclude from Admin Pages in the cookie consent settings.

  • πŸ‡¬πŸ‡§United Kingdom Finn Lewis

    We were seeing exactly the same problem.

    Enabling: "Exclude admin pages." and "Don't show the banner for site administrators (including UID 1)." seems to resolve it for us.

  • πŸ‡ΊπŸ‡ΈUnited States kevinquillen

    Yes, this is still a problem. This should be disabled entirely for administrative paths by default.

  • I ran into this issue myself with the google_tag module.

    It seems to be because google_tag's hook_page_attachments() implementation is ran after eu_cookie_compliance's.

    This means that the disabled_javascripts check doesn't necessarily work as expected.

    I notice that we also implement eu_cookie_compliance_page_attachments_alter() but don't use that to manipulate the attached library definitions. Is there any particular reason we don't handle the disabling of all assets in the alter hook?

    It might also be worth implementing a hook_module_implements_alter() to ensure that the module acts on the attachments last.

    Thoughts are more than welcome!

  • Pipeline finished with Success
    9 months ago
    Total: 48s
    #126134
  • Pipeline finished with Success
    9 months ago
    Total: 47s
    #128497
  • Status changed to Needs review 9 months ago
  • Updated the logic so that all the duplicated logic is handled by a single function, as well as removed all the disable logic from hook_page_attachments() to hook_page_attachments_alter() so that it can detect dynamic libraries such as the google_tag one that might be added.

    Provided a MR which implements the fix in an event subscriber rather than through hooks.

  • Pipeline finished with Success
    9 months ago
    Total: 46s
    #128517
  • πŸ‡¦πŸ‡ΉAustria DrColossos

    The comment from #4 worked as expected. For Google Tag Module: It also works if you enable only "Anonymous Users" only tracking

  • First commit to issue fork.
  • Pipeline finished with Success
    about 1 month ago
    Total: 50s
    #337633
Production build 0.71.5 2024