Skip to content
Source
Sign inSign up
TanStack/query

initialData has no effect if query is in flight #1158

Send to my agent
Closedtannerlinsley opened this issue 8 comments
tannerlinsleycommented

Prepping for a workshop and wanted to use this paradigm, but it feels broken and we should talk about it:

Expected:

  • Click on item before prefetching completes
  • Post view is shown using the initialData (imagine a preview/partial version of the data)
  • Full post is loaded as the original fetch from the prefetch call completes

Thoughts?

PS. This is also the behavior in 2.x

  1. tannerlinsley added labelsenhancement

  2. tannerlinsley added labelsbug

  3. I think this is obviously working exactly how it's designed where if a query is already in flight, it is considered in a loading state from the beginning, which means it won't try and use initialData. I'm wondering how we could model this enhancement though. Maybe something like:

    if (isLoading && initialData) {
      // do initial data stuff
    }
  4. What if you move the initialData into the prefetch?

  5. Yeah that’s the current workaround that works. Just a weird location. It would be awesome to be able to just configure the initial data in a single place in my app.

    Tanner Linsley On Oct 11, 2020, 2:00 AM -0600, Niek Bosch <notifications@github.com>, wrote:

    What if you move the initialData into the prefetch? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

  6. This is where i wonder about just using destructured default data instead of initial data. But then it kinda messes with the whole status rendering concept. I would then have to also check if data exists, even though it's in a hard loading state.... Hmmmm

  7. WHAT IF.... initialData didn't set the cache, but it just overrides the observer state/data.

    So in pseudo code:

    // observer
    if (isLoading && initialData) {
      isSuccess = true
      data = initialData()
    }
  8. I remember there were still reasons to allow initialData to set the data in the cache, so maybe this could even be a new option like placeholderData. 🤷

  9. In SWR, the initial data is local and not saved in the cache, this causes a lot of issues when hydrating from SSR, but with the hydrate feature of RQ this should not be a problem.

  10. Placeholder data has been added

Sign in to join this conversation.