-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix an issue where
useSuspenseQuery
would not respond to cache upda…
…tes when using a cache-first fetch policy with data in the cache when the hook is mounted (#10651) 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. Co-authored-by: Alessia Bellisario <[email protected]>
- Loading branch information
1 parent
3a3a8bc
commit 8355d0e
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@apollo/client': patch | ||
--- | ||
|
||
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters