@classic-homes/maps-svelte 0.2.16 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -100,15 +100,22 @@
100
100
 
101
101
  function setMapStyle(style: string | maplibregl.StyleSpecification) {
102
102
  activeStyleOverride = style;
103
- if (map) {
104
- map.setStyle(style);
105
- // style.load doesn't reliably fire after setStyle() in newer MapLibre versions,
106
- // so we manually trigger a style version bump after the map becomes idle
107
- // See: https://github.com/maplibre/maplibre-gl-js/discussions/2716
108
- map.once('idle', () => {
109
- styleVersion++;
110
- });
111
- }
103
+ if (!map) return;
104
+ const target = map;
105
+ // Every styleVersion bump makes Source and the layer hooks tear down and
106
+ // re-add themselves, so a style swap must bump exactly once. MapLibre fires
107
+ // `style.load` from a diffed setStyle() too (Style.setState), and the
108
+ // handler registered in onMount turns that into the bump. The idle listener
109
+ // is only a fallback for a swap that never fired `style.load` (older
110
+ // MapLibre, or a diff that applied nothing): bumping unconditionally here
111
+ // landed a second bump after the layers had been re-added, and the hooks
112
+ // then found their layers present and skipped re-wiring the click and hover
113
+ // handlers - the map kept rendering, but nothing on it responded.
114
+ const versionBefore = styleVersion;
115
+ target.setStyle(style);
116
+ target.once('idle', () => {
117
+ if (styleVersion === versionBefore) styleVersion++;
118
+ });
112
119
  }
113
120
 
114
121
  const reducedMotion = useReducedMotion();
@@ -98,6 +98,14 @@ export function useLayer(getOptions) {
98
98
  function addLayer() {
99
99
  if (layerAdded || map.getLayer(id)) {
100
100
  layerAdded = true;
101
+ // The layer is on the map but this hook may not own its events: a
102
+ // styleVersion bump drops the handlers and marks the layer as not added,
103
+ // and if the layer survived (or a second bump lands after the first one
104
+ // re-added it) this branch is the only path back. Without the re-attach,
105
+ // the layer renders but every onClick/onHover is silently dead.
106
+ if (!eventHandlerCleanup) {
107
+ eventHandlerCleanup = setupEventHandlers(map, id, source, sourceLayer, onClick, onHover);
108
+ }
101
109
  return;
102
110
  }
103
111
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/maps-svelte",
3
- "version": "0.2.16",
3
+ "version": "0.3.1",
4
4
  "description": "Svelte MapLibre components for Classic Theme",
5
5
  "keywords": [
6
6
  "maps",