Fetcher store always returns `loading: false` despite ongoing Promise
jilio opened this issue · 3 comments
Hello,
I've been experiencing an issue with the fetcher store's loading state in the nanostores/query package. Despite the fetcher returning a Promise that resolves after a delay, the loading state remains false throughout the duration of the Promise.
Here is a simplified code snippet that reproduces the issue:
export const [createFetcherStore, createMutatorStore] = nanoquery({
fetcher: (...keys: string[]) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve({data: 'some data'})
}, 2000)
})
},
})
In this example, I would expect the loading
state to be true
during the 2-second delay before the Promise resolves. However, I'm consistently observing that loading remains false
, despite the fact that the data arrives as expected after the 2 seconds.
I would appreciate any guidance on this issue. If there's any additional information or context that would help diagnose the issue, please let me know and I'll provide it promptly.
Thank you for your time and assistance.
@jilio Yes, I can confirm there's a bug with an initial state there. I'll have a close look there, thanks.
@jilio Fixed in 0.1.2.
Here's a repro in StackBlitz for both conditional and non-conditional stores. Please note that these may require updating @nanostores/react and nanostores libs as well.