swr icon indicating copy to clipboard operation
swr copied to clipboard

isLoading is initially false when there is no data for conditional queries.

Open fmacherey opened this issue 1 year ago • 1 comments

Bug report

I have a query (call them B, see below), which is initally not loading, and is loading and at the end is not loading again (as expected) when there is data, see screenshot with logging information: image

I figured out, that it seems originating from the conditional query I use:

  1. is call query (A), while this the key of query (B) is null, to be disdabled.
  2. when query (A) has data, these are used as args for query (B), so key becomes defined now.
  3. With this pattern I observe the above mentioned bug, so I have to check isLoading and data, to be failsafe.

I am coming from tanstack/query, where you have more options like enable queries or have more then just one loading state, so maybe I am doing s.th. wrong? So please let me know.

Otherwise I would suggest to change isLoading state to take into account, that data !== undefined.

Additional Context

SWR version: 2.2.5 Next: 14.2.5 React: 18.2.0

fmacherey avatar Jul 19 '24 08:07 fmacherey

Can you please show me how to reproduce this in CodeSandbox?

samuel871211 avatar Jan 26 '25 11:01 samuel871211