Document that aggregation of JavaScript files can cause redeclaration

Created on 27 December 2023, 6 months ago
Updated 3 January 2024, 6 months ago

Problem/Motivation

It looks like aggregating several JavaScript files can cause a conflict in the name space, as was seen in πŸ› Multilayer map breaks with JavaScript aggregation when using Maplibre libraries Fixed , which this issue is based on:

After Leaflet 10.2.6 β†’ where maplibre-gl-js & maplibre-gl-leaflet libraries js and css files was embedded in the Leaflet module itself, if you use the Maplibre libraries for example for Vector tiles, and you aggregate JavaScript files, you get a white page, and this message in the console:

Uncaught SyntaxError: redeclaration of const a
note: Previously declared at line 585, column 124988 
js_36Cc25ySfc_bCPZPMGkgRO6_2OjFQNpZD9P35kGaiS8.js:585:125091
js_36Cc25ySfc_bCPZPMGkgRO6_2OjFQNpZD9P35kGaiS8.js:585:124988

Steps to reproduce

NOTE: This issue was resolved in the Leaflet module version 10.2.7 by excluding the maplibre-gl.js from aggregation.

To replicate the problem:

  1. Make the module always load the problematic Maplibre GL library, by changing this line:

    $attached_libraries = ['leaflet/general', 'leaflet/leaflet-drupal'];

    To this:

    $attached_libraries = ['leaflet/general', 'leaflet/leaflet-drupal', 'leaflet/maplibre-gl-leaflet'];

    https://git.drupalcode.org/project/leaflet/-/blob/10.2.x/src/LeafletServ...
  2. To force aggregating the Maplibre library, remove

    { preprocess: false }

    https://git.drupalcode.org/project/leaflet/-/commit/3bd02997151a551f293a...

... and then:

  1. Add a Geofield to a content type, and use Leaflet to show the map
  2. Toggle JavaScript aggregation
  3. See that the map doesn't render with aggregation enabled

Proposed resolution

Figure out how to allow aggregating all JavaScript files.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
Asset libraryΒ  β†’

Last updated about 4 hours ago

No maintainer
Created by

πŸ‡©πŸ‡°Denmark ressa Copenhagen

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

Comments & Activities

Production build 0.69.0 2024