react-use icon indicating copy to clipboard operation
react-use copied to clipboard

Loading state will never turn to error state when geolocation disabled in system preferences

Open gadzhimari opened this issue 5 years ago • 3 comments

What is the current behaviour? Let's imagine, when user first time load the page and geolocation disabled in system preferences in OS, then loading state always stay in this status and user will never know that it's error.

Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than react-use. Paste the link to your CodeSandbox example below: 2021-02-27_09-41-12

What is the expected behavior? Return error from useGeolocation hook, when geolocation disabled in system preferences

A little about versions:

  • OS: macOS Big Sur 11.2.1
  • Browser (vendor and version): Chrome 88.0.4324.192
  • React: 17.0.1
  • react-use: 17.1.1
  • Did this worked in the previous package version? no

gadzhimari avatar Feb 27 '21 06:02 gadzhimari

It looks like passing a position options argument is a workaround for this, though I would also expect the error to occur immediately if location services are disabled.

function App() {
  const { loading, error } = useGeolocation({ timeout: 5000 })

  if (loading) {
    return 'Loading...'
  }

  if (error) {
    return error.message
  }
}

// should render "Timeout expired" after 5 seconds

erikjung avatar Apr 20 '21 13:04 erikjung

You're right, this is the only solution to solve this issue

gadzhimari avatar Apr 20 '21 14:04 gadzhimari

Also worth noting, the usePermission hook might be helpful to detect this before invoking the geolocation hook.

erikjung avatar Apr 20 '21 15:04 erikjung