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-beta] SSR's getDataFromTree(): queries resolved from cache have networkStatus set to loading #5835

Closed
shYkiSto opened this issue Jan 24, 2020 · 5 comments

Comments

@shYkiSto
Copy link

shYkiSto commented Jan 24, 2020

Intended outcome:

getDataFromTree() should populate cache with queries data, so that during final render on the server all server-side queries resolve data from cache, instead of firing off network call, and therefore rendering in loading state.

{
    "data": "<Query Data Goes here>",
    "error": undefined,
    "loading": false,
    "networkStatus": 7
}

> getDataFromTree() pass - start
> { data: false, error: false, loading: true, networkStatus: 1 }
> { data: true, error: false, loading: false, networkStatus: 7 }
> getDataFromTree() pass - end
> { data: true, error: false, loading: false, networkStatus: 7 }

Actual outcome:

While cache is fulfilled with queries data as expected, the queries themselves have networkStatus set to loading. Which is not intended outcome, as the data is ready (pulled from cache), and there's no network request inflight.

{
    "data": "<Query Data Goes here>",
    "error": undefined,
    "loading": true,
    "networkStatus": 1
}

> getDataFromTree() pass - start
> { data: false, error: false, loading: true, networkStatus: 1 }
> { data: true, error: false, loading: false, networkStatus: 7 }
> getDataFromTree() pass - end
> { data: true, error: false, loading: true, networkStatus: 1 }

How to reproduce the issue:

You can find reproduction here https://github.com/shYkiSto/apollo-client-beta-3-ssr:

  1. git clone git@github.com:shYkiSto/apollo-client-beta-3-ssr.git
  2. cd apollo-client-beta-3-ssr && npm install && npm run start
  3. open http://localhost:3000/

or, SSR with Next.js found here: https://github.com/shYkiSto/apollo-client-beta-3-ssr/tree/next-js:

  1. git clone --branch next-js git@github.com:shYkiSto/apollo-client-beta-3-ssr.git
  2. cd apollo-client-beta-3-ssr && npm install && npm run dev
  3. open http://localhost:3000/
  4. check server console output to capture query state changes, or disable JS in your browser to assess server-side renderer result

Versions

  System:
    OS: macOS Mojave 10.14.6
  Binaries:
    Node: 12.12.0 - /usr/local/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.11.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 77.0.3865.90
    Firefox: 69.0.1
    Safari: 13.0.4
  npmPackages:
    @apollo/client: ^3.0.0-beta.25 => 3.0.0-beta.25 
    @apollo/react-ssr: ^4.0.0-beta.1 => 4.0.0-beta.1
@shYkiSto shYkiSto changed the title SSR's getDataFromTree(): queries resolved from cache have networkStatus set to loading [3.0-beta] SSR's getDataFromTree(): queries resolved from cache have networkStatus set to loading Jan 28, 2020
@shYkiSto
Copy link
Author

@benjamn @hwillson wanted to bring this issue to your attention if you are not already aware. Let me know if the description for this issue is misleading, I will be happy to update it

@wesbos
Copy link

wesbos commented Jan 30, 2020

According to this issue, it's because getDataFromTree doesn't run in the browser any longer.

lfades/next-with-apollo#84

@bwhitty
Copy link
Contributor

bwhitty commented Feb 14, 2020

Perhaps also related to #5947

@TimonVS
Copy link

TimonVS commented Jul 15, 2020

I'm not a fan of "me too" comments, but since 3.0 has been released I thought people would like to know that this issue is still present in 3.0.

@shYkiSto
Copy link
Author

shYkiSto commented Aug 5, 2020

I've verified this is no longer an issue with @apollo/client@3.1.2. Thanks!

See #6710 for details

@shYkiSto shYkiSto closed this as completed Aug 5, 2020
@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

No branches or pull requests

4 participants