nanostores / query

⚡️ Powerful data fetching library for Nano Stores. TS/JS. Framework agnostic.
MIT License
228 stars 10 forks source link

Fetcher store always returns `loading: false` despite ongoing Promise #12

Closed jilio closed 1 year ago

jilio commented 1 year ago

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.

dkzlv commented 1 year ago

@jilio Yes, I can confirm there's a bug with an initial state there. I'll have a close look there, thanks.

dkzlv commented 1 year ago

@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.

jilio commented 1 year ago

That is awesome! ✨ Thank you @dkzlv