mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

fix(GeolocateControl): include all GeolocationPositionError properties in error event

Open lucavb opened this issue 2 months ago • 1 comments

Description

Addresses: https://github.com/mapbox/mapbox-gl-js/issues/13576

Problem

In versions 3.15.0+, the GeolocateControl error event is missing code, message, PERMISSION_DENIED, POSITION_UNAVAILABLE, and TIMEOUT properties. Users only receive { target, type } instead of the full error information.

Root Cause

GeolocationPositionError is a native DOM object with non-enumerable properties. When passed directly to new Event('error', error), the Event constructor uses Object.assign() which doesn't copy non-enumerable properties.

Solution

Explicitly extract properties from GeolocationPositionError when creating the error event, matching the pattern already used for the geolocate event (fixed in commit 9a1c893f8).

Before:

this.fire(new Event('error', error));

After:

this.fire(new Event('error', {
    code: error.code,
    message: error.message,
    PERMISSION_DENIED: error.PERMISSION_DENIED,
    POSITION_UNAVAILABLE: error.POSITION_UNAVAILABLE,
    TIMEOUT: error.TIMEOUT
} as GeolocationPositionError));

Here is a screenshot where I tested it in Firefox Screenshot 2025-12-02 at 11 26 57


Launch Checklist

  • [x] Make sure the PR title is descriptive and preferably reflects the change from the user's perspective.
  • [x] Add additional detail and context in the PR description (with screenshots/videos if there are visual changes).
  • [x] Manually test the debug page.
  • [x] Write tests for all new functionality and make sure the CI checks pass.
  • [ ] Document any changes to public APIs. (N/A - this restores existing documented behavior)
  • [ ] Post benchmark scores if the change could affect performance. (N/A - no performance impact)
  • [ ] Tag @mapbox/map-design-team @mapbox/static-apis if this PR includes style spec API or visual changes. (N/A)
  • [ ] Tag @mapbox/gl-native if this PR includes shader changes or needs a native port. (N/A)
  • [ ] Tag @mapbox/gl-native if this PR disables any test because it also needs to be disabled on their side. (N/A)
  • [ ] Create a ticket for gl-native to groom in the MAPSNAT JIRA queue if this PR includes shader changes or features not present in the native side or if it disables a test that's not disabled there. (N/A)

lucavb avatar Dec 02 '25 10:12 lucavb

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Dec 02 '25 10:12 CLAassistant