Endless API call with 0.16.2, strange behavior
See original GitHub issueI just upgraded to jot 0.16.2 and I am seeing some very strange behavior.
I am using an atom to fetch the country of my users:
const currentCountryCode = atom<string>(async () => fetchCurrentCountryCode())
const defaultCountryState = atom(async (get) => get(availableCountriesState).find(({id}) => id == get(currentCountryCode)) || {id: "US", name: "United States"} )
const selectedCountryState = atomWithDefault<Country>((get) => get(defaultCountryState))
Within fetchCurrentCountryCode I am making a request to an external service:
const fetchCurrentCountryCode = async () => {
try {
const rawResponse = await fetch("https://extreme-ip-lookup.com/json/")
return (await rawResponse.json()).countryCode
}
catch (error) {
return null
}
}
All of this works with jotai 0.16.1. But when i upgrade to 0.16.2 this request just hangs forever and my CPU goes crazy.

What is particularly weird is that it doesn’t seem an HTTP issue because I also fetch data from a backend that I host (different server, same domain). I also switched out the geolocation provider and the error stayed the same.
It also seems to have Heisenbug properties. When I add debug statements like this, it makes the request and the problem is gone.
const fetchCurrentCountryCode = async () => {
try {
console.log("making the API call")
const rawResponse = await fetch("https://extreme-ip-lookup.com/json/")
console.log("finished the api call with", rawResponse)
return (await rawResponse.json()).countryCode
}
catch (error) {
console.log("api call failed", error)
return null
}
}
Even worse, I can’t reproduce it on my local system.
The application is hosted on Netflify. You can see a working version with jotai 0.16.1 but I also created a deployment where the error occurs.
Click on “Create Session” to run into the infinite request (open your developer tools before you do that, after that your browser won’t react).
Reproducible in Chrome and Safari.
EDIT: There have been cases where the request worked, might try once or twice to trigger the bug.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (9 by maintainers)
The problem still persists even after removing the
async
keywordPublished: https://www.npmjs.com/package/jotai/v/0.16.4