From e7d2ee7142a0204c1416bdc68eb6b2dfd91e7d08 Mon Sep 17 00:00:00 2001 From: felixpalmer Date: Wed, 17 Dec 2025 05:53:06 +0100 Subject: [PATCH] Invoke setter with default when prop missing (#2560) --- modules/react-mapbox/src/mapbox/mapbox.ts | 17 +++++++++++++++-- modules/react-maplibre/src/maplibre/maplibre.ts | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/modules/react-mapbox/src/mapbox/mapbox.ts b/modules/react-mapbox/src/mapbox/mapbox.ts index c96fd175..bb40fd7c 100644 --- a/modules/react-mapbox/src/mapbox/mapbox.ts +++ b/modules/react-mapbox/src/mapbox/mapbox.ts @@ -85,6 +85,16 @@ export type MapboxProps = Partial & const DEFAULT_STYLE = {version: 8, sources: {}, layers: []} as StyleSpecification; +const DEFAULT_SETTINGS = { + minZoom: 0, + maxZoom: 22, + minPitch: 0, + maxPitch: 85, + maxBounds: [-180, -85.051129, 180, 85.051129], + projection: 'mercator', + renderWorldCopies: true +}; + const pointerEvents = { mousedown: 'onMouseDown', mouseup: 'onMouseUp', @@ -461,10 +471,13 @@ export default class Mapbox { const map = this._map; let changed = false; for (const propName of settingNames) { - if (propName in nextProps && !deepEqual(nextProps[propName], currProps[propName])) { + const propPresent = propName in nextProps || propName in currProps; + + if (propPresent && !deepEqual(nextProps[propName], currProps[propName])) { changed = true; + const nextValue = propName in nextProps ? nextProps[propName] : DEFAULT_SETTINGS[propName]; const setter = map[`set${propName[0].toUpperCase()}${propName.slice(1)}`]; - setter?.call(map, nextProps[propName]); + setter?.call(map, nextValue); } } return changed; diff --git a/modules/react-maplibre/src/maplibre/maplibre.ts b/modules/react-maplibre/src/maplibre/maplibre.ts index 31d2039f..4ef1122a 100644 --- a/modules/react-maplibre/src/maplibre/maplibre.ts +++ b/modules/react-maplibre/src/maplibre/maplibre.ts @@ -80,6 +80,16 @@ export type MaplibreProps = Partial & const DEFAULT_STYLE = {version: 8, sources: {}, layers: []} as StyleSpecification; +const DEFAULT_SETTINGS = { + minZoom: 0, + maxZoom: 22, + minPitch: 0, + maxPitch: 85, + maxBounds: [-180, -85.051129, 180, 85.051129], + projection: 'mercator', + renderWorldCopies: true +}; + const pointerEvents = { mousedown: 'onMouseDown', mouseup: 'onMouseUp', @@ -413,10 +423,13 @@ export default class Maplibre { const map = this._map; let changed = false; for (const propName of settingNames) { - if (propName in nextProps && !deepEqual(nextProps[propName], currProps[propName])) { + const propPresent = propName in nextProps || propName in currProps; + + if (propPresent && !deepEqual(nextProps[propName], currProps[propName])) { changed = true; + const nextValue = propName in nextProps ? nextProps[propName] : DEFAULT_SETTINGS[propName]; const setter = map[`set${propName[0].toUpperCase()}${propName.slice(1)}`]; - setter?.call(map, nextProps[propName]); + setter?.call(map, nextValue); } } return changed;