From b218f21734ae0d4d28cfe44bcfea978d30cd8c5d Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sun, 2 Aug 2026 13:44:11 -0500 Subject: [PATCH] fix: resolve Leaflet window.L not being set in esbuild bundle The esbuild bundle wraps everything in a 'use strict' IIFE, causing the leaflet UMD module to take the CommonJS path instead of setting window.leaflet. The entry point check window.leaflet && !window.L always failed, so window.L was never assigned and the map never initialized. - Add leaflet-global.js to import leaflet-minimal and set window.L before plugins execute (ESM source-order evaluation guarantees this) - Replace the broken window.leaflet check in map-bundle-entry.js with an import of leaflet-global.js --- assets/js/leaflet-global.js | 7 +++++++ assets/js/map-bundle-entry.js | 14 ++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 assets/js/leaflet-global.js diff --git a/assets/js/leaflet-global.js b/assets/js/leaflet-global.js new file mode 100644 index 0000000..07b2622 --- /dev/null +++ b/assets/js/leaflet-global.js @@ -0,0 +1,7 @@ +// Sets window.L from the imported leaflet module. +// Required because esbuild bundles everything in a "use strict" IIFE, +// causing the leaflet UMD to take the CommonJS path instead of setting +// window.leaflet. Plugins and hooks expect window.L to exist. +import * as leafletModule from "../vendor/js/leaflet-minimal.js"; + +window.L = leafletModule; diff --git a/assets/js/map-bundle-entry.js b/assets/js/map-bundle-entry.js index 5bda1cb..a8ff395 100644 --- a/assets/js/map-bundle-entry.js +++ b/assets/js/map-bundle-entry.js @@ -1,11 +1,9 @@ -// Map bundle entry point - combines Leaflet and map plugins -import "../vendor/js/leaflet-minimal.js"; +// Map bundle entry point — combines Leaflet and map plugins. +// +// ESM evaluates side-effect imports in source order, so leaflet-global.js +// runs (and sets window.L) before plugins-optimized.js, which references L. +import "./leaflet-global.js"; import "../vendor/js/plugins-optimized.js"; -// Ensure Leaflet is available as window.L (standard convention) -if (window.leaflet && !window.L) { - window.L = window.leaflet; -} - // Mark bundle as loaded -window.mapBundleLoaded = true; \ No newline at end of file +window.mapBundleLoaded = true;