fix(mapbox): guard getProjection against throw when map style is not ready - #10551
Open
waterWang wants to merge 1 commit into
Open
fix(mapbox): guard getProjection against throw when map style is not ready#10551waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
…ready map.getProjection() can throw (e.g. maplibre-gl's implementation calls this.style.getProjection() without a guard on this.style) when invoked before the map's style is attached — such as on the third addControl call under React 19 StrictMode's dev-only double-invoke of mount effects. The existing optional-chaining only guards against the method being absent, not against the call itself throwing. Wrap the call in try/catch and return 'mercator' as the safe default, matching what callers (getDefaultView / MapboxOverlay#_onAddInterleaved) already expect for the not-ready-yet case. Fixes visgl#10549
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
getProjection()in@deck.gl/mapbox'sdeck-utils.tscan throw when the underlying map's style is not yet assigned, instead of returningundefinedthe way callers (getDefaultView/MapboxOverlay#_onAddInterleaved) expect for "not ready yet, default to mercator".The existing optional-chaining (
map.getProjection?.()) only guards against the method being absent, not against the call itself throwing. In maplibre-gl,Map.prototype.getProjection()isreturn this.style.getProjection()with no guard onthis.style, so calling it before the style exists throws aTypeError.This is reproducible under React 19 StrictMode: the dev-only double-invoke of mount effects adds, removes, and re-adds the same overlay, and the third
addControlcall hits a still-styleless map.Fix
Wrap the
map.getProjection?.()call in a try/catch and return'mercator'as the safe default. This matches the callers' existing expectation —getDefaultViewalready treats any non-'globe' return as mercator.Related
_handleStyleChangecallback path, but the fix did not cover this earlieronAdd-time call site.