fix(geolocate): reset control when the browser permission prompt is dismissed#858
Conversation
MapLibre's GeolocateControl permanently disables its button on any PERMISSION_DENIED (code 1) geolocation error. Browsers report code 1 both for a real denial and when the user merely dismisses the permission prompt without choosing, which left the button stuck in a blocked state with no way to retry. On a code-1 error, query the Permissions API: when the state is not "denied" (i.e. the prompt was dismissed and is still pending), re-create the control so its button returns to a neutral, clickable state and the user can trigger the prompt again. Genuine denials keep MapLibre's disabled state. Fixes #839
✅ Deploy Preview for geolibre-app ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Warning Review limit reached
More reviews will be available in 30 minutes and 38 seconds. Learn how PR review limits work. To continue reviewing without waiting, enable usage-based billing in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
⚡ Cloudflare Pages preview
|
Code reviewThe fix is well-reasoned and the core approach — query the Permissions API after a code-1 error and re-create the control only when the permission state is not Bugs
Quality
Security / PerformanceNothing of concern in this change. CLAUDE.mdNo violations. The changes are scoped to |
Address review feedback: snapshot the control instance at error time and bail out of recreate() if it has been replaced (e.g. the user toggled the control off then on before the async permission check resolved), so a healthy replacement is never torn down. Also guard on this.map so a pending promise after destroy() is a no-op, and clarify that both async branches defer past the error dispatch.
Code reviewOverall the approach is sound — snapshotting Bugs
Quality
Security, Performance, CLAUDE.mdNothing to flag. The Permissions API is read-only, no user input is interpolated, and the change has no effect on the data-flow / store-driven rendering pipeline described in CLAUDE.md. |
Address review feedback: - Reset only when the permission state is 'prompt' (the dismissed-dialog case). A genuine 'denied' keeps MapLibre's disabled state, and a contradictory 'granted' code-1 is left alone instead of being reset. - Add unit tests for handleGeolocateError covering every path: prompt recreates, denied/granted leave it alone, no Permissions API recreates, non-permission errors are ignored, a replaced control is not disturbed, and a destroyed map is a no-op.
Code reviewBugs
Quality
What I checked and found clean
|
Summary
Fixes #839.
MapLibre's built-in
GeolocateControlpermanently disables its button on anyPERMISSION_DENIED(code 1) geolocation error. Browsers report code 1 both for a real denial and when the user merely dismisses/clicks away the permission prompt without making a choice. The result: dismissing the prompt left the geolocate button stuck in the blocked state (icon with a red line) with no way to retry, as reported in the issue.Fix
When the control fires a code-1
error, query the Permissions API:denied(i.e. stillprompt— the dialog was dismissed), re-create the control so its button returns to a neutral, clickable state. Clicking again re-initiates the browser permission prompt.The re-creation is the deactivate/reactivate approach noted in the issue discussion (the control is not otherwise customizable). The error listener is removed when the control is torn down.
Verification
Drove the real web app with Playwright (geolocation + Permissions API mocked to fire a code-1 error), in both light and dark themes:
Also:
npm run buildpasses,tests/map-controller.test.ts(26 tests) passes, pre-commit clean.