-
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 an issue where useSuspenseQuery
would not respond to cache updates when using a cache-first fetch policy with data in the cache when the hook is mounted
#10651
Conversation
…ith data already in the cache This fixes an issue where `useSuspenseQuery` would not respond to cache updates when using a cache-first `fetchPolicy` after the hook was mounted with data already in the cache. This is due to the fact that this hook manages the fetching lifecycle (via `reobserve`) rather than the subscription. We disable fetching when subscribing to the observable since we kick off the fetch in the first render. This however has some downstream issues, since `reobserve` is necessary to set some internal state updates on `ObservableQuery` and `QueryInfo`. In cases where we can fulfill the result via the cache immediately, we avoid calling `reobserve` by subscribing (via the `fetchOnFirstSubscribe` option) to avoid the network request, but this means the interal state updates do not happen. In this case, `QueryInfo`, is initialized with a `networkStatus` of 1, but because we don't call `reobserve`, this value never gets updated to 7 even though `observableQuery.getCurrentResult()` is able to correctly set this value to 7. This caused issues where `broadcastQueries` was not sending notifications since `queryInfo` avoids broadcasting to in-flight queries for fetch policies other than cache-only and cache-and-network. This attempts to patch the behavior expected from in `reobserve` by marking the queryInfo as ready if we detect that the result is also ready.
🦋 Changeset detectedLatest commit: 4098548 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Ultimately I may decide to refactor These types of PRs always give me a bit of pause since it feels wrong that I would need to "patch" some of this behavior as a one-off case. I'd love to harden this a bit more so that it doesn't feel like I'm trying to hack around the existing implementation. |
/release:pr |
A new release has been made for this PR. You can install it with |
I can confirm this fixes the issue by installing this snapshot release in the Spotify demo and running through the reproduction steps from #10478 |
Fixes #10478
Fixes an issue where mounting
useSuspenseQuery
while using acache-first
fetch policy (the default) with data in the cache would not respond to cache updates after the initial result.See this comment with more information on the mechanics behind why this was not working properly.
Checklist: