-
-
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
isLoading doesnt become true
when state=pending
, even if there was never any data due to an error on a previous fetch in 2.2.5
#4449
Comments
Hmm. We did tweak that logic in #4364 - maybe related? (listed as "The isLoading flag logic was improved to handle errors when a query hook tries to subscribe." in https://github.com/reduxjs/redux-toolkit/releases/tag/v2.2.4 ) |
Ok this is a major issue. I've just had the similar issue where when an endpoint errors, it Downgrade to v2.2.3 and the behaviour is correct. We have most of our application doing validation using |
As usual, we would really need a repro or a Replay ( https://replay.io/record-bugs ) in order to be able to see what's going on. Doubly so because I'm looking at the diff between 2.2.3 and 2.2.5 and barely seeing any actual logic changes in RTKQ: https://github.com/reduxjs/redux-toolkit/compare/v2.2.3..v2.2.5 |
Does this do the trick? Let me know if you need something else. Made changes to To reproduce |
Gotcha, thanks. I'll be up front and say I'm pretty tired atm and don't have the brainpower to look into this this evening. I might be able to look at it this weekend, but can't guarantee that. |
All G. I will pin to Thank you for the prompt reply. |
I had a look at this comment and the PR which introduced the changes. Shouldn't the If I remove the change, |
If I'm honest, I'm irritated how that would have any influence on Could it be that the behaviour of |
Hi @phryneas In my code, we use Doesn't this codesandbox show the issue? https://codesandbox.io/p/sandbox/cranky-platform-vk2myz?file=%2Fsrc%2Ffeatures%2Ftime%2FTimeList.tsx%3A102%2C4 Our components are setup like this const { isLoading, isError, data } = useGetSomeQuery()
if (isLoading) return <Loading />
if (isError) return <Error />
const {property} = data
return <Component {...property} /> If the query failed and errored, then the first time shows When I revert this change https://github.com/reduxjs/redux-toolkit/compare/v2.2.3..v2.2.5#diff-73c1158d8e3a3d7e65694702b3a588f33308713c72ac94cf478f341dd4cf0494R693, everything works as expected. |
I confirm on our side the issue is definitely with |
I'm sorry for the slow response time - I just moved and now I have to take care of a small puppy here, so while that's a wonderful experience, I barely have the time to do anything beyond that. I am sorry, but I am still not 100% sure that we have cornered this bug, and I still believe we are looking at it from the wrong direction. The reason for that is simple: no code that modifies
So while now there might be situations where an overlap between those might look differently, it's hard for me to believe that at any point in time I believe that right now, a narrow error description hinders us from seeing the actual problem - and we need to understand the underlying problem to fix this. We can't just roll back the other change, as it itself fixed a bug. With the demo, I have to be honest, I'm not sure what I'm looking at. Because there are three queries on the page, the successful queries seem to come from the other two queries, and after a (honestly, suspiciously long) waiting time, the impacted query flips to "error". Could someone maybe take a stab at extracting a test that shows this behaviour? |
Thanks @phryneas Could you point me towards the selector for I shall try and make a smaller demo and will post soonish. Thanks again. |
@david10sing : it's calculated here, separately from the hooks, and stored directly in the Redux state:
|
Here's a simpler sandbox. To reproduce: |
Ah, so the scenario is
|
true
when state=pending
, even if there was never any data due to an error on a previous fetch in 2.2.5
Do you want to do a PR? The fix would probably be something like -const isLoading = (!lastResult || lastResult.isLoading || lastResult.isUninitialized) && !hasData && isFetching
+const isLoading = (!lastResult || lastResult.isLoading || lastResult.isUninitialized || lastResult.error) && !hasData && isFetching |
I can do the PR. I had that Also why does the |
Because at that point in a time, we are Going back over #1349 and #4364, I'm starting to believe that change should never have been made - instead we should probably have tweaked the docs. The state we are in currently breaks all guarantees that we make in TypeScript - like if @smacpherson64 pulling you in here - I fear we'll have to undo that PR, as it was breaking a much more common use case. I'm sorry 😞 |
Understood and no worries! Sorry to have caused this trouble! For now, for the current use case will likely do something like: #4364 (comment) Does the initial concept of checking specifically for a previous error have the same issue? EDIT: adds link to previous discussion |
Thinking through this again, I do not believe it would. In both cases If I am understanding this, the
Is the following breakdown correct?
Are you thinking the documentation should become something like:
Edit: thoughts on is state of documentation. |
Just upgraded from 2.2.3 to 2.2.5
Previously we had a check doing
if (isLoading || isError) return null;
, it seems with a 401 error where we previously had isError to true, it is now false. Strangely, isFetching is now true (although error is present with a 401 in status).I don't see a relevant change in the patch note, have I missed something or is it a bug ?
The text was updated successfully, but these errors were encountered: