-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
queryFn is called twice in Suspense mode #324
Comments
It appears to be somewhere in
And yet, if I debug/ Possibly a race condition? Or possibly the |
Ah. Removing I'd love to shake my head ruefully and say "ah, it's because the tests are just too damn fast!" but this happens in production too sadly, even with slow APIs. |
This is indeed a funky issue. Still thinking here... keep up the info, it's helping. |
same problem😂 |
Hey @tannerlinsley As I'm not 100% sure this is the same case here I will just share here the issues I refer to useMemo gets called twice with Suspense |
So, I was able to reproduce this thanks to @simoncarpinter fork and the cuse was this line: https://github.com/tannerlinsley/react-query/blob/8a6ec246deaef9f4a0c1b32298874e3e74dc93c5/src/utils.js#L134 . As I'm a bit new to react and js in general, I'm not sure why we need throw this Promise in general? |
I found this answer by Dan the Man, on another github issue that seems to suggest a recommended solution facebook/react#14490 (comment) |
@ofer-h we need to throw the promise because that's how From what I can tell from reading the code, what should be happening is that we start fetching (great). Then, we throw whatever From my understanding of those linked tickets, the @lindskogen that could be useful -- using a ref for storing the |
Legend, thanks Tanner :). I tried the refs but didn't get very far. |
Moved to separate issue as this is not the cause |
Per the title, when using
useQuery
with{ suspense: true }
, the supplied query function will be called twice.See simoncarpinter@cc09457 for details, opening a PR now that adds the test. I haven't yet spotted the actual bug.
The text was updated successfully, but these errors were encountered: