Advagg isn't correctly concatenating JS associated with Treetable

Created on 26 September 2022, over 2 years ago
Updated 21 October 2023, about 1 year ago

Steps to replicate

Using Token and Advagg modules together, triggers a browser inspector console error:

Result

Uncaught TypeError: this is undefined

Expected result

JS to be able to execute without any errors

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom lukus

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.

  • First commit to issue fork.
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MariaDB 10.3.22
    last update over 1 year ago
    Not currently mergeable.
  • @goz opened merge request.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MariaDB 10.3.22
    last update over 1 year ago
    77 pass
  • 🇫🇷France goz

    I have the same issue. I also use advagg, but i find the issue is not caused by advagg, but even Drupal js aggregation make the javascript error.

    To reproduce :
    - Install Drupal 9.5.x
    - Install Token module and another module using tokens (Metatag, rabbit hole etc)
    - Disable Drupal JS Aggregation
    - Go to page where token link with tree widget is displayed (your node form with metatag field or node form with rabbit hole settings available)
    - No errors, in console. If you have a wysiwyg for example, everything works fine.
    - Enable Drupal JS Aggregation
    - Go back to your node form
    - JS error display in console and wysiwyg is no more available.

    The patch #2 does not solve the solution.

    May be the reason is: when we aggregate js, some other scripts add "use strict" instructions, but when strict mode is enabled, the keyword this is undefined in a function invocation in strict mode.

    The MR replace 'this' by 'window' global variable to make this available in strict mode.

    I make this issue critical since it breaks all javascripts execution when js aggregation is enabled.

  • 🇨🇭Switzerland berdir Switzerland

    Don't know anything about this, never had this problem but I'm happy to commit this if someone more knowledgeable can confirm this makes sense and it's not ausing any sort of BC issue.

  • Status changed to RTBC over 1 year ago
  • 🇺🇦Ukraine cosolom

    Patch from #6 works for me. Thanks. I also had the issue that page is broken because of

    TypeError: Cannot read properties of undefined (reading 'TreeTable')
  • 🇨🇭Switzerland berdir Switzerland

    I'm going to need a review of someone who understands JS better than me.

    I'm really confused about the current situation with that file and what the change exactly does and if there's any possible impact this could have. Looking at the treetable github project, I'm not even sure what version we exactly have here. This doesn't seem to match the latest version but seems closer to an open merge request there.

  • 🇮🇳India rushiraval

    This is update for jquery treetable. MR !40 can merged or your can repalace js/jquery.treetable.js file from
    https://github.com/ludo/jquery-treetable/blob/master/jquery.treetable.js

  • 🇺🇸United States andy-blum Ohio, USA

    The change to the JS shouldn't have any side-effects. I agree with @GoZ's assessment that running the JS in strict mode is likely the cause of the issue. At Lullabot, we've made the decision to write all JS using strict mode, but likely haven't encountered this exact error since I don't believe we're using advagg.

    in attempting to follow @GoZ's instructions, I couldn't reproduce the issue. That being said, using `this` outside of object-oriented code raises red flags and I think this change to a more explicit `window` is a good decision. I've attached some screenshots to hopefully demonstrate that the changes of `this` to `window` in the scope of an IIFE do not impact



  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MariaDB 10.3.22
    last update about 1 year ago
    77 pass
    • Berdir committed 5828fe0e on 8.x-1.x authored by GoZ
      Issue #3311852 by GoZ, lukus: Advagg isn't correctly concatenating JS...
  • Status changed to Fixed about 1 year ago
  • 🇨🇭Switzerland berdir Switzerland

    Merged, thank you.

  • 🇮🇳India rushiraval

    @Berdir I think it will be good if you replace js/jquery.treetable.js file from
    https://github.com/ludo/jquery-treetable/blob/master/jquery.treetable.js because it is updated version then current patch.

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

Production build 0.71.5 2024