react-apollo-hooks icon indicating copy to clipboard operation
react-apollo-hooks copied to clipboard

fetchPolicy="network-only" still returns data from the cache

Open bradleyayers opened this issue 6 years ago • 5 comments

It seems like even when I'm using network-only that data from the cache is being returned immediately. I would have expected that the rendering phases would be:

{ data: {},           loading: true }  // render 1
{ data: { foo: {…} }, loading: false } // render 2
// done

Instead what happens is that if data from the cache exists, at render 1 data will actually be populated with the cache data.

The React Apollo docs make it clear this should never happen:

network-only: This fetch policy will never return you initial data from the cache. Instead it will always make a request using your network interface to the server. This fetch policy optimizes for data consistency with the server, but at the cost of an instant response to the user when one is available.

For now I'm using a wrapper that returns {} when loading=true and fetchPolicy=no-cache or fetchPolicy=network-only.

bradleyayers avatar Feb 13 '19 03:02 bradleyayers

@bradleyayers it seems it's an issue with apollo-client which is already fixed in master:

  • https://github.com/apollographql/apollo-client/pull/4352
  • https://github.com/apollographql/react-apollo/issues/556

trojanowski avatar Feb 22 '19 12:02 trojanowski

Apollo Client 2.5.0 is already released. @bradleyayers could you please confirm if it solved the problem for you?

trojanowski avatar Mar 01 '19 16:03 trojanowski

still happening on the latest client. 2.5.2, definitely an issue with apollo-client

https://github.com/apollographql/react-apollo/issues/556#issuecomment-468886874

wrod7 avatar Mar 11 '19 17:03 wrod7

Who found a workaround for this?

ziedHamdi avatar Nov 13 '19 13:11 ziedHamdi

I need a solution for this too. fetchPolicy: "network-only" is not working.

adrianescat avatar Nov 20 '19 01:11 adrianescat