
How I Fixed a Geolocation Permission Bug in a Next.js App
While contributing to Accuguide — an open source platform that helps people discover accessible places and services — I came across an annoying bug where the browser was asking for location permission on every single page load , not just when it was actually needed. In this article I'll walk you through what caused it, how I tracked it down, and how I fixed it. The Problem When you visit any page on Accuguide, the browser would immediately pop up: "accuguide.org wants to know your location" This happened even on pages like /info/about or /legal/privacy where location data is completely irrelevant. It was bad UX and also hurt the site's Lighthouse/PageSpeed score under the "Avoids requesting permissions on page load" audit. The expected behavior was simple: only ask for location permission on the /search page, and only when the user has actually typed a search query. Finding the Bug The location logic lived in a React context called LocationProvider in app/contexts/location-context.tsx
Continue reading on Dev.to JavaScript
Opens in a new tab




