diff --git a/.changeset/tasty-pillows-ring.md b/.changeset/tasty-pillows-ring.md new file mode 100644 index 00000000000..5c0f9643bb5 --- /dev/null +++ b/.changeset/tasty-pillows-ring.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": minor +--- + +Add `watchFragment` method to the cache and expose it on ApolloClient, refactor `useFragment` using `watchFragment`. diff --git a/src/react/hooks/useFragment.ts b/src/react/hooks/useFragment.ts index f9bd31bb784..1fd9b379bc1 100644 --- a/src/react/hooks/useFragment.ts +++ b/src/react/hooks/useFragment.ts @@ -84,7 +84,10 @@ export function useFragment( const subscription = cache.watchFragment(options).subscribe({ next: (result) => { resultRef.current = result; - // TODO: add comment back here + // If we get another update before we've re-rendered, bail out of + // the update and try again. This ensures that the relative timing + // between useQuery and useFragment stays roughly the same as + // fixed in https://github.com/apollographql/apollo-client/pull/11083 clearTimeout(lastTimeout); lastTimeout = setTimeout(forceUpdate) as any; },