react-query-firebase icon indicating copy to clipboard operation
react-query-firebase copied to clipboard

1.0.0-dev7: useFirestoreDocumentData does not update invalidated data (react 18.2.0, react-query 3.39.2)

Open alex-kowalczyk opened this issue 3 years ago • 1 comments

After bumping @react-query-firebase/firestore (mostly to workaround React 18.2.0 peer dep), the query invalidation stops working. I do not have time to create minimal repro sandbox. Posting as a heads-up to others. Reverting to 0.4.2 fixes the issue.

Simplified pseudo-code:

// Disable auto-refetching to avoid noise.
const queryClient = new QueryClient({defaultOptions: {queries: {staleTime: Infinity, cacheTime: Infinity}}});
<QueryClientProvider client={queryClient}>...</...>

const ref = docRef.withConverter(converter);
// simplified, just to demonstrate invalidation method.
const onSuccess = async () => ({await queryClient.invalidateQueries({predicate: () => true})});
const {data} = useFirestoreDocumentData(path, ref),  // not a subscription
      {mutate} = useFirestoreDocumentMutation(docRef, {merge: true}, {onSuccess});

Actual results when calling mutate({field: someVal})

  • The value is updated is Firebase
  • onSuccess is called
  • The query is invalidated as expected and refetched, according to network/logs/react-query-devtools
  • According to debug logs, after refetching the converter applied on ref is called with proper "new" value

Until this point, works as expected. But the values are not updated in:

  • query data in react-query-devtools,
  • useFirestoreDocumentData hook data in React Dev Tools,
  • the app.

alex-kowalczyk avatar Nov 01 '22 08:11 alex-kowalczyk

Having the same issue, let us know if you need some repro, but basically:

  • everything default,
  • useFirestoreDocumentData(someRef)
  • mutate,
  • invalidate query in onSuccess
  • useFirestoreDocumentData re-triggered but same value returned, confirmed using React Query dev tools, just the time and query count changed

I also tried some random sleep(1s) or more but it did not have any effect. Firestore persistence/offline not enable (web).

HugoGresse avatar Mar 03 '23 16:03 HugoGresse