You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Suspense mode, data is always the fetch response (so you don't need to check if it's undefined).
It turns out that if we use suspense mode + conditional fetching, SWR is going to suspend the execution only when it gets a valid id, resulting in an undefined data object meanwhile.
As a user, I would expect that SWR throws component rendering at the moment of invocation, even — if the fetcher execution hasn't started yet — because right now I end up having to do undefined checks anyway.
The docs state that:
It turns out that if we use suspense mode + conditional fetching, SWR is going to suspend the execution only when it gets a valid
id
, resulting in an undefineddata
object meanwhile.As a user, I would expect that SWR throws component rendering at the moment of invocation, even — if the fetcher execution hasn't started yet — because right now I end up having to do undefined checks anyway.
Here's a working sample: https://codesandbox.io/s/conditional-fetching-suspense-b72ii
I am not quite sure if that's actually the intended behavior. If so, I'd say it definitely deserves some notice on the docs.
Also, I tried finding some similar issues but I couldn't find any related one.
Thanks 🙏
The text was updated successfully, but these errors were encountered: