apollographql / react-apollo

:recycle: React integration for Apollo Client
https://www.apollographql.com/docs/react/
MIT License
6.85k stars 790 forks source link

useQuery with onCompleted: infinite loop. #4044

Open vendramini opened 4 years ago

vendramini commented 4 years ago

Hello!

I had this code before updating to v3:

const {
        data: dataEvents,
        loading: loadingEvents,
        error: errorEvents,
    } = useQuery(
        getEventsQuery,
        {
            fetchPolicy: "network-only",
            onCompleted() {
                //do stuffs
            }
        }
    );

And it works without problem. After updating to v3, even an empty onCompleted callback produces an infinite loop in my component, requesting the query forever. If I take the onCompleted off, everything works well.

I found a related issue: https://github.com/apollographql/react-apollo/issues/3353#issuecomment-521130366 but the fix didn't work for me.

Thanks :)

System:
    OS: Linux 5.0 Linux Mint 19.1 (Tessa)
  Binaries:
    Node: 12.16.3 - ~/.nvm/versions/node/v12.16.3/bin/node
    Yarn: 1.21.1 - /usr/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v12.16.3/bin/npm
  Browsers:
    Chrome: 83.0.4103.116
    Firefox: 78.0.1
  npmPackages:
    @apollo/client: ^3.0.1 => 3.0.1 
    apollo-upload-client: ^13.0.0 => 13.0.0 
    next-with-apollo: ^5.1.0 => 5.1.0