From 13fa56e79bac59b4295087780485567c3f531d42 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Thu, 25 Jan 2024 12:31:51 -0500 Subject: [PATCH] chore: adds changeset, reverts removal of comment --- .changeset/tasty-pillows-ring.md | 5 +++++ src/react/hooks/useFragment.ts | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changeset/tasty-pillows-ring.md 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; },