Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0.0-beta.27] Querying data that is already in the cache sets loading to true #5869

Closed
vishwam opened this issue Jan 28, 2020 · 11 comments
Closed

Comments

@vishwam
Copy link
Contributor

vishwam commented Jan 28, 2020

This is a repeat of issue #5757 created by @od1k about this a few weeks back and marked as fixed in beta.23: unfortunately, it's still reproing in beta.27.

Intended outcome:
When running some query:

  const {
    loading,
    data
  } = useQuery(SOME_QUERY);

we expect that loading will be false if data is already in the cache (with default or cache-only fetchPolicy).

Actual outcome:
loading is true even when the requested data is in the cache.

I cannot tell if this is expected behaviour or not but it is definitely different from Apollo Client 2.6.

I've updated @od1k's original repro to beta.27 and published it as a code sandbox here for easier debugging.

The repro code, in essence, first fetches all data in ALL_DATA_QUERY and then fetches a subset in CLOCK_SPEED_QUERY. The expected behavior is that the second query (triggered when the button is clicked) only renders once with loading: false, but it actually renders twice (see console log).

@vishwam
Copy link
Contributor Author

vishwam commented Jan 30, 2020

added details from original issue if it helps get more traction on the issue. For now, the mitigation is to stop relying on loading and just check for !data instead.

@shYkiSto
Copy link

shYkiSto commented Feb 3, 2020

I think it's the same issue described in #5835, where queries resolved with data have loading state during SSR (and subsequent first render on the client when the page hydrates).

@jebonfig
Copy link

Still an issue on 3.0.0-beta.34:

For a component containing a single useQuery hook with fetchPolicy: cache-only I'm seeing the following occur:

The component renders for the first time, the loading prop is true, the data is populated with the query result.
The component renders again, the loading prop is false, the same data is populated with the query result.

Seems like this component should only render once, with loading = false and the data being returned?

@jfrolich
Copy link

jfrolich commented Feb 18, 2020

Same here. I also tested this on beta-35, and there the issue is still occurring.

@suppayami
Copy link

Tried on 3.0.0-beta.44, still occurring

@macrozone
Copy link

can also reproduce with

   "@apollo/client": "^3.0.0-beta.44",
    "@apollo/react-ssr": "^4.0.0-beta.1",

@novembrea
Copy link

Any progress on this?

@yury-tyshkevich
Copy link

can also reproduce with

    "@apollo/client": "^3.0.0-rc.4",
    "@apollo/react-ssr": "^4.0.0-beta.1",

@macrozone
Copy link

seems still be the case with the final version of @apollo/client !

@hwillson
Copy link
Member

hwillson commented Aug 3, 2020

I've verified this is no longer an issue with @apollo/[email protected]. Thanks!

@hwillson hwillson closed this as completed Aug 3, 2020
@BrendonSled
Copy link

When using {ssr:true} this issue is not fixed. The client is set to loading while the data is there.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants