Fix getPaintProperty throwing on unknown paint property names - #13729
Open
akashchamp wants to merge 1 commit into
Open
akashchamp wants to merge 1 commit into
akashchamp wants to merge 1 commit into
Conversation
akashchamp
requested review from
stepankuzmin
and removed request for
a team
September 23, 2026 19:23
|
Hey, @akashchamp 👋 Thanks for your contribution to Mapbox GL JS! Important: This repository does not accept direct merges. All changes go through our internal review process. What happens next:
Please respond to any review comments on this PR. For more details, see CONTRIBUTING.md. |
|
|
map.getPaintProperty(layerId, name) crashed with an unhelpful
TypeError ("Cannot read properties of undefined (reading 'value')")
when name was not a real paint property for the layer's type, e.g.
map.getPaintProperty('background', 'fill-radius').
Style#setPaintProperty already guards its lookups with
StyleLayer#isPaintProperty before touching the underlying
TransitionablePropertyValue map; Style#getPaintProperty did not, so
the internal Transitionable#getValue lookup dereferenced an undefined
entry directly.
Mirror that existing check in Style#getPaintProperty: validate the
property name (accounting for the '-transition' suffix, which is
also handled by StyleLayer#getPaintProperty) before delegating, fire
a descriptive ErrorEvent when it is not a paint property for the
layer's type, and return undefined instead of throwing.
Fixes mapbox#6033
akashchamp
force-pushed
the
fix/6033-validate-getpaintproperty-name
branch
from
September 25, 2026 18:21
e68def5 to
b78392c
Compare
This branch has not been deployed
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.
Fixes #6033.
Problem
map.getPaintProperty(layerId, name)throws an unhelpfulTypeErrorwhennameis not a real paint property for that layer's type, instead of reporting a clear user error:This happens because
StyleLayer#getPaintProperty→Transitionable#getValueindexes into its internal property map with the raw (unchecked) name and immediately dereferences.valueon the result, which isundefinedfor an unrecognized property.Fix
Style#setPaintPropertyalready guards this same lookup withStyleLayer#isPaintPropertybefore touching the property map.Style#getPaintPropertydid not have an equivalent guard. This PR adds one: before delegating tolayer.getPaintProperty(name), it checkslayer.isPaintProperty(name)(accounting for the-transitionsuffix, whichStyleLayer#getPaintPropertyalso special-cases) and, if the name isn't a paint property for that layer's type, fires a descriptiveerrorevent and returnsundefinedinstead of throwing — consistent with this project's convention of usingerrorevents to report user errors (seeCONTRIBUTING.md).Scope note:
Style#setPaintPropertycurrently has a similar unguardedlayer.getPaintProperty(name)call of its own (for its dirty-check), which means it can still throw for an unknown property name today, despite the validation described above. That's a separate, narrower bug (previously tracked and closed as #6030) from what this issue (#6033) asks for, so I left it alone here to keep this change focused — happy to follow up separately if that's wanted.Verification
mainwith a throwaway test callingstyle.getPaintProperty('background', 'fill-radius')— confirmed it threwCannot read properties of undefined (reading 'value')before this change.test/unit/style/style.test.ts(describe('Style#getPaintProperty', ...)):undefined, fires anerrorevent whose message matches/fill-radius.*not a paint property/.<property>-transitionname (e.g.background-color-transition) still resolves correctly, guarding against a regression in that pre-existing, separately-handled case.npm run test-unit -- test/unit/style/style.test.ts— 161 passed, 1 pre-existing skip, 0 failed.npm run test-unit -- test/unit/style/style_imports.test.ts test/unit/style/style_layer_index.test.ts test/unit/style/style_layer.test.ts test/unit/ui/map/properties.test.ts test/unit/ui/map.test.ts(paint-property-related tests) — all passed, no regressions.npm run tsc— exit 0.npm run lint— exit 0.CHANGELOG.mdentry underUnreleased/Bug fixesperCONTRIBUTING.md.Launch Checklist
@mapbox/map-design-team@mapbox/static-apis. (N/A — no style spec API or visual changes.)@mapbox/gl-native. (N/A — no shader changes, no native port needed.)AI disclosure: I used Claude (Anthropic) to help investigate this issue and draft this fix and its tests. I reviewed the change, ran the verification above myself, and stand behind the PR.