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

Query invalidation in mutations does not work properly

Open mickeywu opened this issue 5 months ago • 5 comments

Current Behavior

In the DataConnect React library, query invalidation in mutations doesn't work as described when passing in a reference instance without parameters.

As described in the documentation, if I pass in just the reference to the query, it should invalidate all queries cached:

const createMovie = useDataConnectMutation(createMovieRef, {
  invalidate: [getMovieRef],
});

This will actually also trigger a TypeScript error:

Type 'GetMovieRef' is not assignable to type 'QueryRef<unknown, unknown> | (() => QueryRef<unknown, unknown>)'.
  Type 'GetMovieRef' is not assignable to type '() => QueryRef<unknown, unknown>'.
    Target signature provides too few arguments. Expected 1 or more, but got 0.ts(2322)

Even after ignoring the TS error, the query does not get invalidated after the mutation executes in the app.

However, it works as intended if a parameter is specified to invalidate a specific record:

const createMovie = useDataConnectMutation(createMovieRef, {
  invalidate: [getMovieRef({ id: "1" })],
});

Expected Behavior

Passing in a query reference without parameters to the invalidate option in mutations should invalidate ALL of its cached queries.

mickeywu avatar Aug 16 '25 05:08 mickeywu

Hey thanks for opening this, We'll take a look and provide updates as soon as they're available

cabljac avatar Aug 18 '25 09:08 cabljac

@mickeywu Hey just to check, you're using firebase SDK version 11 with tanstack-query-firebase?

cabljac avatar Aug 18 '25 13:08 cabljac

Hi @cabljac, I tested with both Firebase SDK v11 as well as v12. The issue occurs in both versions. Thanks for looking into it!

mickeywu avatar Aug 18 '25 23:08 mickeywu

Hi @cabljac, was wondering if the team has had a chance to look into this issue? Cheers.

mickeywu avatar Sep 03 '25 23:09 mickeywu

@mickeywu I cannot reproduce this. Are you able to provide an MCVE?

maneesht avatar Oct 28 '25 20:10 maneesht