-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Fix extra useQuery
result frames
#9599
Conversation
This option allows delaying/canceling any/all network traffic for the given query, and should prevent making stray network requests on behalf of useQuery queries whose useEffect callbacks never fire.
This removes the UNNEEDED_FRAME from the second test added in PR #9508, which currently causes the test to fail, though the version without the UNNEEDED_FRAME is how we ultimately want useQuery to behave. I believe the other test is correct to have the repeated frame: #9508 (comment)
Closes #9508, now that its tests are both accurate and passing.
Final cleanup to address #9508.
TODO Make the 5000 constant configurable.
375d668
to
8292081
Compare
8292081
to
58cab4e
Compare
@yusufumac Thank you! Would you mind opening a new issue, ideally with a small reproduction? I have some guesses about what the problem might be, but it would be great to see some concrete code. Are you saying Does any of that sound familiar/plausible from your debugging? |
WatchQueryOptions.fetchBlockingPromise was introduced recently in #9599, and probably needed more time to bake on the release-3.6 branch before the final v3.6.0 release. This commit removes fetchBlockingPromise from the public WatchQueryOptions API, but continues passing an equivalent Promise<boolean> when calling observable.reobserve (whenever the useQuery options change). This means we no longer block fetches for the initial call to useQuery, but that should already be handled (even in <React.StrictMode>) by waiting until the ObservableQuery gets its very first subscriber (in useEffect) to initiate the first network request. Since options.fetchBlockingPromise was intended for internal use and was never documented, I am hopeful we still have time to remove it in a patch version (likely 3.6.1).
@yusufumac An update relevant to your concerns: PR #9636 removes the |
@benjamn Thanks for the update. It was a busy week, so I couldn't create a reproducible case for you. I downgraded to 3.5.10 and didn't have the same issue. I will try 3.6.1 and will let you know if the issue still there. |
This PR builds on #9508, fixing the unexpected frame by transitioning to a
loading: true
result synchronously when variables change or the query is refetched.Since we do not want to commit to making any network requests synchronously during rendering, I have come up with a new way to block all network requests, by passing a
fetchBlockingPromise: Promise<boolean>
option that intercepts a part of the request pipeline that is already safely asynchronous.As a happy side effect, this
fetchBlockingPromise
technique should also prevent making any network requests for extraObservableQuery
objects created during development when using React's<StrictMode>
, since the extra component renders are never mounted, and thususeEffect
never fires, leaving thefetchBlockingPromise
unresolved until it times out and the fetch gets silently canceled (as desired).