profile
viewpoint

Ask questionscurrentObservable.query.fetchMore is not a function

We encounter this error when there is page switching to/from a page that calls useQuery and attempts to call the fetchMore function it returns. We have fixed this by checking the route before executing fetchMore, but it seems like something that should be fixed.

It looks like a similar issue to this issue: https://github.com/apollographql/react-apollo/issues/3368. Looking at the code, I see that this call checks that the currentObservable query exists before calling the function (https://github.com/apollographql/react-apollo/blob/master/packages/hooks/src/data/QueryData.ts#L100) but this call assumes that the query exists and calls it anyway (https://github.com/apollographql/react-apollo/blob/master/packages/hooks/src/data/QueryData.ts#L443). It seems there are a few other places where this pattern occurs in this QueryData file, so it seems a similar fix would be good here.

Intended outcome:

The fetchMore function handles when the currentObservable query does not exist instead of throwing an undefined exception.

Actual outcome:

react-apollo throws

react-hooks.esm.js:80 Uncaught TypeError: Cannot read property 'fetchMore' of undefined
    at o.obsFetchMore (react-hooks.esm.js:80)
    at S (utils.ts:222)
    at onFetchMoreRecipes (Recipes.tsx:190)
    at c (RecipesTable.tsx:46)
    at hooks.tsx:30

How to reproduce the issue:

On Chrome browser, navigate to/from a page that makes a request with useQuery and that will attempt to call fetchMore to another page (that may or may not make a similar request). When the original request resolves, this error is thrown.

Version

react-apollo v3.1.3

System: OS: macOS Mojave 10.14.6 Binaries: Node: 12.13.0 - ~/.nvm/versions/node/v12.13.0/bin/node Yarn: 1.19.2 - /usr/local/bin/yarn npm: 6.12.0 - ~/.nvm/versions/node/v12.13.0/bin/npm Browsers: Chrome: 79.0.3945.79 Firefox: 71.0 Safari: 13.0.4

apollographql/react-apollo

Answer questions RIP21

I can confirm that we're getting the same issues on fetchMore of undefined. Mostly it happens when you change route unmounting component that has pending infinity scroll-triggered request.

useful!
source:https://uonfu.com/
answerer
Andrey Los RIP21 Revolut Krakow, Poland http://ololos.space/ Senior Frontend Engineer at Revolut. In love with: singing (music), coding, games, self-improvement and Formula 1.
Github User Rank List