|
4 | 4 | */
|
5 | 5 |
|
6 | 6 | let leafletInstance = null;
|
7 |
| -let isLoaded = false; |
8 | 7 |
|
9 | 8 | /**
|
10 | 9 | * Get the Leaflet instance, loading it conditionally based on build type
|
11 | 10 | * @returns {Object|null} Leaflet instance or null if not available in current build
|
12 | 11 | */
|
13 | 12 | export function getLeaflet() {
|
14 |
| - if (isLoaded) { |
15 |
| - return leafletInstance; |
16 |
| - } |
17 |
| - |
18 |
| - // In test environment, always try to load Leaflet for testing |
19 |
| - const shouldLoadLeaflet = |
20 |
| - (typeof process !== "undefined" && |
21 |
| - process.env && |
22 |
| - process.env.NODE_ENV === "test") || |
23 |
| - // eslint-disable-next-line no-undef |
24 |
| - (typeof __INCLUDE_LEAFLET__ !== "undefined" && __INCLUDE_LEAFLET__); |
| 13 | + if (leafletInstance !== null) return leafletInstance; |
25 | 14 |
|
26 |
| - if (shouldLoadLeaflet) { |
27 |
| - try { |
28 |
| - // eslint-disable-next-line import/no-dynamic-require,global-require |
29 |
| - leafletInstance = require("leaflet/dist/leaflet"); |
30 |
| - isLoaded = true; |
31 |
| - return leafletInstance; |
32 |
| - } catch (error) { |
33 |
| - console.warn("Failed to load Leaflet:", error); |
34 |
| - leafletInstance = null; |
35 |
| - } |
36 |
| - } else { |
37 |
| - const buildType = |
38 |
| - // eslint-disable-next-line no-undef |
39 |
| - typeof __BUILD_TYPE__ !== "undefined" ? __BUILD_TYPE__ : "unknown"; |
40 |
| - console.info(`Leaflet not available in ${buildType} bundle`); |
| 15 | + try { |
| 16 | + // eslint-disable-next-line import/no-dynamic-require,global-require |
| 17 | + leafletInstance = require("leaflet/dist/leaflet"); |
| 18 | + } catch (error) { |
| 19 | + console.warn("Failed to load Leaflet:", error); |
41 | 20 | leafletInstance = null;
|
42 | 21 | }
|
43 | 22 |
|
44 |
| - isLoaded = true; |
45 | 23 | return leafletInstance;
|
46 | 24 | }
|
47 | 25 |
|
48 |
| -const L = getLeaflet(); |
49 |
| - |
50 |
| -export default L; |
| 26 | +export default getLeaflet(); |
0 commit comments