Problem/Motivation
In https://www.drupal.org/project/collapsiblock/issues/3418361, it looks like there was an un-minified version of the Collapsiblock JavaScript introduced in https://git.drupalcode.org/project/collapsiblock/-/commit/9257fec05fc1e2.... However, it seems that this new JS is setting a global variable for L, which is interfering with the JavaScript from the Leaflet contrib module. This issue is present in the 4.2.0 version of Collapsiblock, but is not present in the previous versions (e.g., 4.1.0).
For sites using both Collapsiblock and Leaflet contrib modules, when updating Collapsiblock to version 4.2.0, all Leaflet maps fail to display in views, on nodes, or anywhere else one might have Leaflet. Google Chrome’s Console in the browser inspection tools shows some of the following console errors:
leaflet.drupal.js?v=10.2.7:985 Uncaught TypeError: Cannot read properties of undefined (reading 'extend')
at leaflet.drupal.js?v=10.2.7:985:38
at leaflet.drupal.js?v=10.2.7:1017:3
leaflet_more_maps.js?sfacao:25 Uncaught TypeError: Cannot read properties of undefined (reading 'extend')
at leaflet_more_maps.js?sfacao:25:31
drupal.js?v=10.2.7:64 Uncaught TypeError: Cannot read properties of undefined (reading 'get')
at loadMap (leaflet.drupal.js?v=10.2.7:23:74)
at HTMLDivElement.<anonymous> (leaflet.drupal.js?v=10.2.7:168:13)
at Function.each (jquery.min.js?v=3.7.1:2:3129)
at ce.fn.init.each (jquery.min.js?v=3.7.1:2:1594)
at Object.<anonymous> (leaflet.drupal.js?v=10.2.7:14:26)
at Function.each (jquery.min.js?v=3.7.1:2:3179)
at Object.attach (leaflet.drupal.js?v=10.2.7:8:9)
at drupal.js?v=10.2.7:166:24
at Array.forEach (<anonymous>)
at Drupal.attachBehaviors (drupal.js?v=10.2.7:162:34)

Steps to reproduce
composer require 'drupal/leaflet:^10.2'and then enable the modulecomposer require 'drupal/leaflet_more_maps:^2.2'and then enable the module- Verify that you are using Collapsiblock version 4.1.0
- Visit
/admin/config/development/performanceand disableAggregate JavaScript filesfor the purposes of being able to easier see which files experience the error - Clear Drupal cache
- Visit
/admin/config/system/leaflet-more-maps/demo - Verify you see the free maps on the page (e.g., the “Esri World Imagery (zoom 0..17)” map)

composer update drupal/collapsiblockand verify you are now using version 4.2.0 of Collapsiblock- Clear Drupal cache
- Visit
/admin/config/system/leaflet-more-maps/demoagain - Expected result: I should see the free maps on the
/admin/config/system/leaflet-more-maps/demopage (e.g., the “Esri World Imagery (zoom 0..17)” map) - Actual result: no maps appear on the
/admin/config/system/leaflet-more-maps/demopage.
Proposed resolution
- Compare the contents of the un-minified collapsiblock.js file for 4.2.0 https://git.drupalcode.org/project/collapsiblock/-/blob/4.2.0/theme/dist/collapsiblock.js?ref_type=tags with its minified predecessor from 4.1.0 https://git.drupalcode.org/project/collapsiblock/-/blob/4.1.0/theme/dist/js/collapsiblock.min.js to determine what differences could be causing this?
- Consider narrowing the scope of Collapsiblock's
Lso it does not get set globally?
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| Screenshot 2024-06-14 at 6.57.49 PM.png | 511.54 KB | cainaru | |
| Screenshot 2024-06-18 at 1.43.09 PM.png | 500.07 KB | cainaru | |
| Screenshot 2024-06-18 at 1.42.34 PM.png | 7.86 MB | cainaru |
Issue fork collapsiblock-3455500
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
Comment #2
cainaruComment #4
darvanenThanks for the detailed report @cainaru, I'm working on finding a fix for this now. It was caused by the move to vite from gulp and my less-than-perfect understanding of vite config.
Comment #6
darvanen@larowlan came up with the solution for this in Slack:
you want this
theme/dist/collapsiblock.js: { minified: true, attributes: {type: module} }which causes it to render as
<script type="module">Comment #11
darvanenHaving trouble with the pipeline for 4.x.
I can cut a release for 4.2.1 in the interim though.
Comment #14
darvanenComment #16
ressaThanks @cainaru and @darvanen. I got two warnings, after updating contrib modules and Drupal core:
Everything did work as expected after going through the update, clearing cache, etc., but to understand why the warnings got there in the first place, I searched and found this issue. As I wrote, everything works as expected on https://arst.dk/kort?data=radon where both Collapsiblock and Leaflet are used, so thanks for the report and update quickly thereafter.