From 3b9a32592b732dd8cada3bc7b2cb6484b0882974 Mon Sep 17 00:00:00 2001 From: martinfrancois Date: Sat, 22 Aug 2026 23:35:57 +0200 Subject: [PATCH] fix: declare the published packages side-effect free Without a `sideEffects` field a bundler has to assume that importing any module might do something on its own, so it cannot drop the components an app never imports. An app that imports only Map, Source and Layer still ships ScaleControl, GeolocateControl, TerrainControl, FullscreenControl, GlobeControl, LogoControl and Marker. Measured on a Next.js 16 app that imports AttributionControl, Layer, Map, NavigationControl, Popup and Source from react-map-gl/maplibre, by reading the module list out of the build's source maps: before 26 modules bundled, all 7 unused control wrappers present after 18 modules bundled, 0 unused control wrappers present all 6 used components still present client chunks 2774929 -> 2771505 bytes raw, 815085 -> 814253 gzipped Same result with webpack and with Turbopack. The packages are safe to mark. Across all three module trees there are no CSS imports and no module-scope statements that execute work; every top-level line is an import, an export or a declaration. The only top-level calls are the memo() and forwardRef() wrappers, which return a component and do nothing else. The one prototype assignment, the getContext hijack in maplibre.ts, sits inside a method behind an `if (props.gl)` and restores the original on the next call, so it never runs on import. Also tried adding /*#__PURE__*/ to the memo() and forwardRef() calls, which is the usual companion change. It made no further difference once the field was set, so it is not included here. --- modules/main/package.json | 1 + modules/react-mapbox/package.json | 1 + modules/react-maplibre/package.json | 1 + 3 files changed, 3 insertions(+) diff --git a/modules/main/package.json b/modules/main/package.json index d8f73d34b..9836355b7 100644 --- a/modules/main/package.json +++ b/modules/main/package.json @@ -15,6 +15,7 @@ }, "license": "MIT", "type": "module", + "sideEffects": false, "exports": { "./mapbox": { "types": "./dist/mapbox.d.ts", diff --git a/modules/react-mapbox/package.json b/modules/react-mapbox/package.json index 7556e767d..05876af38 100644 --- a/modules/react-mapbox/package.json +++ b/modules/react-mapbox/package.json @@ -14,6 +14,7 @@ }, "license": "MIT", "type": "module", + "sideEffects": false, "types": "dist/index.d.ts", "main": "dist/index.cjs", "module": "dist/index.js", diff --git a/modules/react-maplibre/package.json b/modules/react-maplibre/package.json index 9142e575f..43221ff27 100644 --- a/modules/react-maplibre/package.json +++ b/modules/react-maplibre/package.json @@ -14,6 +14,7 @@ }, "license": "MIT", "type": "module", + "sideEffects": false, "types": "dist/index.d.ts", "main": "dist/index.cjs", "module": "dist/index.js",