Skip to content

Commit

Permalink
Add comment explaining use of fetchOnFirstSubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Dec 8, 2022
1 parent 0ba6b06 commit 9cff58d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/react/hooks/useSuspenseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,21 @@ function useWatchQueryOptions<TData, TVariables>({

return {
...watchQueryOptions,
fetchOnFirstSubscribe: false,
query,
errorPolicy:
errorPolicy || defaultOptions?.errorPolicy || DEFAULT_ERROR_POLICY,
fetchPolicy:
fetchPolicy || defaultOptions?.fetchPolicy || DEFAULT_FETCH_POLICY,
notifyOnNetworkStatusChange: suspensePolicy === 'always',
// By default, `ObservableQuery` will run `reobserve` the first time
// something `subscribe`s to the observable, which kicks off a network
// request. This creates a problem for suspense because we need to begin
// fetching the data immediately so we can throw the promise on the first
// render. Since we don't subscribe until after we've unsuspended, we need
// to avoid kicking off another network request for the same data we just
// fetched. This option toggles that behavior off to avoid the `reobserve`
// when the observable is first subscribed to.
fetchOnFirstSubscribe: false,
variables: compact({ ...defaultOptions?.variables, ...variables }),
};
}, [options, query, defaultOptions]);
Expand Down

0 comments on commit 9cff58d

Please sign in to comment.