-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Loading should not be initially true when the data is provided server-side [reproduction provided] #6651
Comments
Can you make it simply runnable from https://codesandbox.io/s/github/daryn-k/apollo-client-3-ssr-demo But from your looking at your code can you maybe this?
|
No, the reason of the problem is not in Rewrote some stuff and it's ready: https://codesandbox.io/s/optimistic-dust-wu0u6 For hide |
Maybe its me but your title claims it doesn't work. While in the sample it works, only the fact it renders twice because of 'loading' suddenly being true. But data is not being fetched again (filled from window.apolloState). So the restore mechanism works, only the 'loading: true' effect is unwanted behaviour and seems like the bug. Maybe adjust the title more about loading state, which is indeed new since v3. Good luck! Which is also briefly described here: #6631 (comment) |
Sorry, but you are not correct. You didn't understand what is the problem. Twice fetching is not normal behavior.
Everything worked and works perfectly with Author of the comment you linked to is complaining on One more time. It's actual outcome: It's Intended outcome: |
"Author of the comment you linked to is complaining on renderToString, but I don't have any problem with this method." please read the second issue mentioned: "But there's a second issue, which is client side. The first call to useQuery for a given query, with ssr: true, returns the correct data, but with loading: true. The cache is correctly pre-populated and no network request is sent, and it immediately does an update/rerender with loading:false, but all the extra rerendering has a noticeable performance imact." exactly your issue, it doesnt get the data twice! So your "So if cache populated it will not fetch data one more time." statement is not correct. You dont see any xhr request happening client-side! Only the loading state is incorrect! If you remove that you will see no hydration warning anymore. Its just for a split second it starts in loading state, then it takes the data from your initial data state. |
https://wu0u6.sse.codesandbox.io/ no xhr call client-side, data populated from initial state. Only problem is loading:true for split second: |
Oops... You are absolutely correct. Sorry, it's my bad. Right, there is no second fetch. Give me some time to dig into this problem. If I write:
there is no error. |
Yes, so change the title into this bug behaviour :) Loading should not be initially true when the data is provided server-side. |
When will this bug be fixed? |
Should be fixed here: #6710 |
Intended outcome
new InMemoryCache().restore(window.apolloState || {})
should populate the cache fromwindow.apolloState
. It works withapollo-client
(version 2.6.x), but not with@apollo/client
.Actual outcome
new InMemoryCache().restore(window.apolloState || {})
doesn't populate the cache, it's empty. By the way, there is no any problem with server and server-side rendering. The problem is in client side. It doesn't restore the cache. We are getting the warning from React because of that.How to reproduce
Here are demos:
Github:
https://github.com/daryn-k/apollo-client-3-ssr-demo.git
[link]CodeSandBox:
https://codesandbox.io/s/optimistic-dust-wu0u6
[link]You can comment and uncomment the lines with 🕷 and ✅ and clearly see how it works with old version 2.6.x and doesn't work with the 3.x.
./src/client.js
./src/server.js
The text was updated successfully, but these errors were encountered: