You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to access getStyle in a child component of Map or MapProvider. My goal is to access the layers and other attributes that are only available on MapgetStyle() in a self contained child component.
This explodes in mapbox-gl and maplibre-gl.
The workaround for this is, to setLoaded(true); in onLoad and only call .getStyle() after onLoad ran.
Expected Behavior
a. Can react-map-gl guard against this error and return undefined instead?
b. Can react-map-gl improve the error message? ("reading .version" is very unhelpful to debug the issue.)
c. I suggest to extend the docs for the useMap hook to explain this behavior. See also #2118
Line // 🔴🔴 THIS DOES NOT WORK (throw) is already active
==> The app crashed
Environment
See Stackblitz.
Logs
----------START// FIRST RENDERmymap=>undefined// expected, first render----------1BEFOREmymap?.getMap()?.getStyle()mymap?.getMap()?.style?.stylesheet?.modified=>undefinedmymap?.getMap()?.getStyle()=>"FALLBACK for mymap?.getMap()?.getStyle()"----------2AFTERmymap?.getMap()?.getStyle()----------START// SECOND RENDERmymap==>undefined----------1BEFOREmymap?.getMap()?.getStyle()mymap?.getMap()?.style?.stylesheet?.modified=>undefinedmymap?.getMap()?.getStyle()=>"FALLBACK for mymap?.getMap()?.getStyle()"----------2AFTERmymap?.getMap()?.getStyle()----------START// THIRD RENDERmymap=>{getMap: ƒ,getCenter: ƒ,getZoom: ƒ,getBearing: ƒ, …}----------1BEFOREmymap?.getMap()?.getStyle()mymap?.getMap()?.style?.stylesheet?.modified=>undefined// ??? What is going on here? React just stops the render and starts again?----------START// ANOTHER RERENDERmymap=>{getMap: ƒ,getCenter: ƒ,getZoom: ƒ,getBearing: ƒ, …}----------1BEFOREmymap?.getMap()?.getStyle()mymap?.getMap()?.style?.stylesheet?.modified=>undefined// ??? Again…----------START// ANOTHER RERENDERmymap=>{getMap: ƒ,getCenter: ƒ,getZoom: ƒ,getBearing: ƒ, …}----------1BEFOREmymap?.getMap()?.getStyle()mymap?.getMap()?.style?.stylesheet?.modified=>undefined// ??? Again…----------START// ANOTHER RERENDERmymap=>{getMap: ƒ,getCenter: ƒ,getZoom: ƒ,getBearing: ƒ, …}----------1BEFOREmymap?.getMap()?.getStyle()mymap?.getMap()?.style?.stylesheet?.modified=>undefined=>Error: Cannotreadpropertiesofundefined(reading'version')Theaboveerroroccurredinthe<MapView>component:
atMapView(https://react-ts-bx4sty.stackblitz.io/~/MapView.tsx:35:39)
atMapProvider(https://react-ts-bx4sty.stackblitz.io/turbo_modules/react-map-gl@7.0.21/dist/es5/components/use-map.js:36:42)atAppConsideraddinganerrorboundarytoyourtreetocustomizeerrorhandlingbehavior.Visithttps://reactjs.org/link/error-boundariestolearnmoreabouterrorboundaries.maplibre-gl.js:35Error: Cannotreadpropertiesofundefined(reading'version')maplibre-gl.js:35Error: Cannotreadpropertiesofundefined(reading'version')maplibre-gl.js:35Error: Cannotreadpropertiesofundefined(reading'version')
The text was updated successfully, but these errors were encountered:
I'm not sure why it should be the responsibility of this library. After getMap() you are calling native methods on the map instance. That is subject to whatever behavior the underlying library has.
Description
I am trying to access
getStyle
in a child component of Map or MapProvider. My goal is to access the layers and other attributes that are only available onMap
getStyle()
in a self contained child component.This explodes in
mapbox-gl
andmaplibre-gl
.The workaround for this is, to
setLoaded(true);
inonLoad
and only call.getStyle()
afteronLoad
ran.Expected Behavior
a. Can
react-map-gl
guard against this error and return undefined instead?b. Can
react-map-gl
improve the error message? ("reading .version" is very unhelpful to debug the issue.)c. I suggest to extend the docs for the useMap hook to explain this behavior. See also #2118
Steps to Reproduce
mapbox-gl
handleOnload
work as expected// 🔴🔴 THIS DOES NOT WORK (throw)
maplibre-gl
// 🔴🔴 THIS DOES NOT WORK (throw)
is already activeEnvironment
See Stackblitz.
Logs
The text was updated successfully, but these errors were encountered: