-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RTK Query returns cached data for different query arguments, unless remount is forced #4575
Comments
Those are both expected, yes:
For more details, see: |
Ok, thanks for taking the time to reply (especially given it's explained in the docs - I swear I looked before posting the issue). It still feels counterintuitive to me, as though the default behavior should be the other way around. I would have thought the most common use case for a query hook with args is to return a different resource based on the provided arg. // first render
const { data, isLoading } = useGetPokemonQuery(pikachu.id) // <- data is pikachu
// second render
const { data, isLoading } = useGetPokemonQuery(bulbasaur.id) // <- data is still pikachu? this is unexpected Anyway I'm nitpicking. This issue can be closed. Thanks again. |
The idea here is to prevent big layout changes. Usually it's preferrable to keep old data on the screen for a second longer instead of having the whole screen replaced with a spinner and then immediately have the data flicker in 50ms later. |
No. It's not. |
I do not think this is expected behavior, but could be mistaken. Any advice would be appreciated.
I have query definition like this:
It's called in a component like this:
When that component re-renders with a new user prop, (i.e. with a different value for
user.entraid_user_id
), I can see the correct network request firing, but while that request is in flight the value ofdata
returned by the query hook is the value for the previously rendered user, and the value ofisLoading
remainsfalse
.When the network request is rejected (404), still the value of
data
is for the previously rendered user, andisLoading
remains false.So both while the network request is in flight and after it resolves, the other rendered profile details match the newly rendered user, but the profile photo is of the wrong person.
If I set the query option
{ refetchOnMountOrArgChange: true }
this has no effect. Same behavior.If I force a remount by giving the component a
key={user.id}
prop, then it behaves as expected.data
is undefined,isLoading
istrue
, and when the 404 is returned,data
remains undefined andisLoading
isfalse
. In this case it doesn't matter whether I setrefetchOnMountOrArgChange
- it works with or without it.I have lots of experience with tanstack query, but thiis my first time using RTKQuery. Is this expected behavior? Seems a bit counterintuitive to me if it is.
Thanks.
The text was updated successfully, but these errors were encountered: