React-query: Disabled query gets called anyway by the refetch feature

Created on 25 Jun 2020  路  5Comments  路  Source: tannerlinsley/react-query

Describe the bug
I have some disabled queries awaiting for some change on my components.
And even if the value doesn't change, the queryFn is called at each refetchInterval.

To Reproduce

const [neverUpdatedValue] = React.useState(null);
useQuery({
    queryKey: ["test", neverUpdatedValue],
    queryFn: (key, value) => {
        console.log(key, value);
        return Promise.resolve();
    },
    config: {
        enabled: !!neverUpdatedValue,
        refetchInterval: 2000
    }
});

I set up a sandbox derived from your "Basic" example :
https://codesandbox.io/s/busy-moon-pon1t?file=/src/index.js

The refretchInterval triggers the queryFn even if it is disabled.

Expected behavior
Do not trigger the queryFn.

Desktop (please complete the following information):

  • Version 2.2.3
released

Most helpful comment

Just released a fix again. 馃憤

All 5 comments

@tannerlinsley , Can you please guide me, I would love to work on this to fix if this is an issue? If you could help me how to approach I can start looking into it. Thank You.

Yeah sure. This line here would need an extra check before running anything that there is at least one query that is enabled (instance.config.enabled).

:tada: This issue has been resolved in version 2.4.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Still isn't fixed in the released version mentionned above.
https://codesandbox.io/s/sad-roentgen-8g0yc?file=/src/index.js
The issue #648 probably reports the same problem.

Just released a fix again. 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CreativeTechGuy picture CreativeTechGuy  路  3Comments

ivowork picture ivowork  路  5Comments

jackmellis picture jackmellis  路  5Comments

michaeljota picture michaeljota  路  6Comments

benediktviebahn picture benediktviebahn  路  4Comments