initialData has no effect if query is in flight #1158
Send to my agentPrepping for a workshop and wanted to use this paradigm, but it feels broken and we should talk about it:
- https://codesandbox.io/s/agitated-colden-0v0mp?file=/src/index.js
- Hover over item (it will start prefetching, which artificially takes 3 seconds)
- Click on item before prefetching completes
- Post view is shown in the "hard"
isLoadingstate.
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
tannerlinsley added labelsenhancement
tannerlinsley added labelsbug
What if you move the initialData into the prefetch?
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.
This is where i wonder about just using destructured default data instead of initial data. But then it kinda messes with the whole
statusrendering concept. I would then have to also check ifdataexists, even though it's in a hard loading state.... HmmmmWHAT IF....
initialDatadidn't set the cache, but it just overrides the observer state/data.So in pseudo code:
// observer if (isLoading && initialData) { isSuccess = true data = initialData() }I remember there were still reasons to allow
initialDatato set the data in the cache, so maybe this could even be a new option likeplaceholderData. 🤷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.
Placeholder data has been added
boschni(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
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: