Repository navigation
fix(mapbox): guard getProjection against throw when map style is not ready - #10551
Merged
chrisgervang merged 6 commits intoOct 11, 2026
Merged
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
Collaborator
|
Thank you for your contribution! Please include unit regression tests |
Pessimistress
approved these changes
Aug 19, 2026
53 of 66 tasks
|
chrisgervang
added a commit
that referenced
this pull request
Oct 22, 2026
…ready (#10551) * fix(mapbox): guard getProjection against throw when map style is not 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 #10549 * Apply suggestion from @chrisgervang * test(mapbox): cover getProjection fallback before style is set --------- Co-authored-by: waterWang <[email protected]> Co-authored-by: Chris Gervang <[email protected]> Co-authored-by: Chris Gervang <[email protected]> (cherry picked from commit 539eeac)
Collaborator
|
Released in deck.gl 9.4.1. Thanks @waterWang! |
12 tasks done
chrisgervang
added a commit
that referenced
this pull request
Oct 30, 2026
…ready (#10551) * fix(mapbox): guard getProjection against throw when map style is not 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 #10549 * Apply suggestion from @chrisgervang * test(mapbox): cover getProjection fallback before style is set --------- Co-authored-by: waterWang <[email protected]> Co-authored-by: Chris Gervang <[email protected]> Co-authored-by: Chris Gervang <[email protected]> (cherry picked from commit 539eeac)
Collaborator
|
Released in deck.gl 9.3.12. Thanks! |
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.Note
Low Risk
Small defensive change in projection detection during overlay setup; default behavior matches existing mercator fallback expectations.
Overview
getProjectionin@deck.gl/mapboxno longer crashes when the underlying map has no style yet. Themap.getProjection?.()call is wrapped in try/catch; on throw (e.g. maplibre-gl beforestyleexists), it returns'mercator'instead of propagating aTypeError. Globe detection is unchanged once projection info is available.A unit test asserts mercator fallback when
getProjectionthrows and still returnsglobewhen the style exposes{type: 'globe'}.Reviewed by Cursor Bugbot for commit 19a7f13. Bugbot is set up for automated code reviews on this repo. Configure here.