Skip to content

Fix promoteId crash on features with null properties - #194

Merged
mourner merged 1 commit into
mapbox:mainfrom
spokodev:fix/promoteid-null-properties
Jul 2, 2026
Merged

Fix promoteId crash on features with null properties#194
mourner merged 1 commit into
mapbox:mainfrom
spokodev:fix/promoteid-null-properties

Conversation

@spokodev

@spokodev spokodev commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

promoteId throws and crashes the whole geojsonvt(...) call when a feature has properties: null, which is valid GeoJSON (RFC 7946 section 3.2 allows a null properties member).

geojsonvt({
  type: 'Feature',
  properties: null,
  geometry: {type: 'Point', coordinates: [0, 0]}
}, {promoteId: 'id'});
// TypeError: Cannot read properties of null (reading 'id')

A single such feature anywhere in the input produces no tiles. The other id paths already tolerate null properties: generateId: true works, and no id option works, so this is an inconsistency in the promoteId path.

Cause

src/convert.js reads geojson.properties[options.promoteId] with no guard against a null (or absent) properties.

Fix

Guard the access. null && x / undefined && x resolve to a falsy id, which is normalized to no id downstream (the same result as a missing property key), so behavior is unchanged for features that do have properties.

Testing

Added a test that tiles a properties: null feature with promoteId. It throws on the current code and passes with the fix. The full suite stays green (29 tests).

promoteId read geojson.properties[options.promoteId] without a null
guard, so a feature with properties: null (valid GeoJSON per RFC 7946)
threw a TypeError and crashed the whole geojsonvt() call. The other id
paths (generateId, none) already tolerate null properties. Guard the
access so a null-properties feature resolves to no id, as it does for a
missing property key.
@spokodev
spokodev requested a review from a team as a code owner July 2, 2026 05:05
@mourner
mourner merged commit 6948037 into mapbox:main Jul 2, 2026
1 check passed
@spokodev
spokodev deleted the fix/promoteid-null-properties branch July 8, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants