Conditions for firing onDiscarded and onLoadingSlow #2302
Unanswered
crogers-dr
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I'm working on upgrading from [email protected] to 2.0.0 and react 17 to 18.
In my existing implementation I have a hook using swr that is reused in a few places. I believe one instance is hitting both the onDiscarded callback and the onLoadingSlow callback. Both callbacks are definitely firing and should be from the same component, there is only one instance of the component I'm checking the callbacks on.
The component uses the onLoadingSlow callback to show a message explaining it. So it receives the data from another call using the same key, then eventually shows the slow warning despite already having data.
There are probably other guards but I didn't see an explicit scenario for it here https://github.com/vercel/swr/blob/main/core/use-swr.ts#L314; so I'm wondering if it is expected that an instance of an swr hook could be both discarded and loadingSlow?
I wasn't able to recreate exactly in a code sandbox. But here it is just in case
https://codesandbox.io/p/sandbox/ancient-sun-yc1ru6?file=%2Fcomp%2FuseAdmin.ts
Beta Was this translation helpful? Give feedback.
All reactions