From d57e469018096dcec4cb8a7d0b05e5064e2e7c90 Mon Sep 17 00:00:00 2001 From: Xiaoji Chen Date: Thu, 20 Mar 2025 09:41:27 -0700 Subject: [PATCH] Remove support() check (#2508) --- .../main/src/mapbox-legacy/components/map.tsx | 26 +++++++------------ modules/react-mapbox/src/components/map.tsx | 26 +++++++------------ modules/react-maplibre/src/components/map.tsx | 26 +++++++------------ 3 files changed, 30 insertions(+), 48 deletions(-) diff --git a/modules/main/src/mapbox-legacy/components/map.tsx b/modules/main/src/mapbox-legacy/components/map.tsx index f6b4b29d..4eb3d0a1 100644 --- a/modules/main/src/mapbox-legacy/components/map.tsx +++ b/modules/main/src/mapbox-legacy/components/map.tsx @@ -59,24 +59,18 @@ function _Map(props: MapProps, ref: React.Ref) { throw new Error('Invalid mapLib'); } - // workerUrl & workerClass may change the result of supported() - // https://github.com/visgl/react-map-gl/discussions/2027 setGlobals(mapboxgl, props); - if (!mapboxgl.supported || mapboxgl.supported(props)) { - if (props.reuseMaps) { - mapbox = Mapbox.reuse(props, containerRef.current); - } - if (!mapbox) { - mapbox = new Mapbox(mapboxgl.Map, props, containerRef.current); - } - contextValue.map = createRef(mapbox); - contextValue.mapLib = mapboxgl; - - setMapInstance(mapbox); - mountedMapsContext?.onMapMount(contextValue.map, props.id); - } else { - throw new Error('Map is not supported by this browser'); + if (props.reuseMaps) { + mapbox = Mapbox.reuse(props, containerRef.current); } + if (!mapbox) { + mapbox = new Mapbox(mapboxgl.Map, props, containerRef.current); + } + contextValue.map = createRef(mapbox); + contextValue.mapLib = mapboxgl; + + setMapInstance(mapbox); + mountedMapsContext?.onMapMount(contextValue.map, props.id); }) .catch(error => { const {onError} = props; diff --git a/modules/react-mapbox/src/components/map.tsx b/modules/react-mapbox/src/components/map.tsx index 2e567b12..fbd52b39 100644 --- a/modules/react-mapbox/src/components/map.tsx +++ b/modules/react-mapbox/src/components/map.tsx @@ -59,24 +59,18 @@ function _Map(props: MapProps, ref: React.Ref) { throw new Error('Invalid mapLib'); } - // workerUrl & workerClass may change the result of supported() - // https://github.com/visgl/react-map-gl/discussions/2027 setGlobals(mapboxgl, props); - if (!mapboxgl.supported || mapboxgl.supported(props)) { - if (props.reuseMaps) { - mapbox = Mapbox.reuse(props, containerRef.current); - } - if (!mapbox) { - mapbox = new Mapbox(mapboxgl.Map, props, containerRef.current); - } - contextValue.map = createRef(mapbox); - contextValue.mapLib = mapboxgl; - - setMapInstance(mapbox); - mountedMapsContext?.onMapMount(contextValue.map, props.id); - } else { - throw new Error('Map is not supported by this browser'); + if (props.reuseMaps) { + mapbox = Mapbox.reuse(props, containerRef.current); } + if (!mapbox) { + mapbox = new Mapbox(mapboxgl.Map, props, containerRef.current); + } + contextValue.map = createRef(mapbox); + contextValue.mapLib = mapboxgl; + + setMapInstance(mapbox); + mountedMapsContext?.onMapMount(contextValue.map, props.id); }) .catch(error => { const {onError} = props; diff --git a/modules/react-maplibre/src/components/map.tsx b/modules/react-maplibre/src/components/map.tsx index 7d8fe2ae..1300d120 100644 --- a/modules/react-maplibre/src/components/map.tsx +++ b/modules/react-maplibre/src/components/map.tsx @@ -59,24 +59,18 @@ function _Map(props: MapProps, ref: React.Ref) { throw new Error('Invalid mapLib'); } - // workerUrl & workerClass may change the result of supported() - // https://github.com/visgl/react-map-gl/discussions/2027 setGlobals(mapboxgl, props); - if (!mapboxgl.supported || mapboxgl.supported(props)) { - if (props.reuseMaps) { - maplibre = Maplibre.reuse(props, containerRef.current); - } - if (!maplibre) { - maplibre = new Maplibre(mapboxgl.Map, props, containerRef.current); - } - contextValue.map = createRef(maplibre); - contextValue.mapLib = mapboxgl; - - setMapInstance(maplibre); - mountedMapsContext?.onMapMount(contextValue.map, props.id); - } else { - throw new Error('Map is not supported by this browser'); + if (props.reuseMaps) { + maplibre = Maplibre.reuse(props, containerRef.current); } + if (!maplibre) { + maplibre = new Maplibre(mapboxgl.Map, props, containerRef.current); + } + contextValue.map = createRef(maplibre); + contextValue.mapLib = mapboxgl; + + setMapInstance(maplibre); + mountedMapsContext?.onMapMount(contextValue.map, props.id); }) .catch(error => { const {onError} = props;