apollographql / react-apollo

:recycle: React integration for Apollo Client
https://www.apollographql.com/docs/react/
MIT License
6.85k stars 787 forks source link

`getDataFromTree` not working with apollo local state #3486

Open lifeiscontent opened 5 years ago

lifeiscontent commented 5 years ago

Relevant issue here: https://github.com/zeit/next.js/pull/8673#discussion_r323275265

during SSR apollo local state should be resolved because the client may have access to the local state resolvers / cache like it does in this example.

carlows commented 5 years ago

Is there a workaround for this?

lifeiscontent commented 5 years ago

@hwillson might know, but from what I've found currently, no.

lasseborly commented 5 years ago

Phew I'm also suffering from this atm. Might just go back and downgrade.

rnacken commented 5 years ago

I have the same issue. I created a small repo based off on Nextjs' with-apollo example, and described the behaviour in this SO question: https://stackoverflow.com/questions/58174010/apolllo-client-state-preset-cache-does-not-work-on-server-side-render I do a cache-write with initial data when I init the apollo-client. However, this cache gets ignored by the SSR (first) render, where I get returned loading: true, data: undefined. Which triggers an error, because I want to destructure the data immediately. Second server render & client render show correct data.

The repo: https://github.com/rnacken/next-with-apollo-client-state-cache

devops398 commented 4 years ago

Experiencing same issue, any workaround to this? My project contains a lot of @client directive and facing this is a pure surprise, this should be mentioned in docs if @client doesn't work on SSR.

niamleeson commented 4 years ago

Just ran into this issue. This completely nullfies the benefit of using Apollo as a local state management solution.

hwillson commented 4 years ago

Would anyone here be able to provide a small, runnable reproduction? The repro provided in https://github.com/apollographql/react-apollo/issues/3486#issuecomment-537420370 is fixed by updating to 3.1.3, but it isn't related to the original issue here.

lifeiscontent commented 4 years ago

ping @HaNdTriX do you still have that example available showcasing the bug we ran into in the next.js repo?

PerminovEugene commented 4 years ago

I have the same issue. getDataFromTree calls render with empty apollo storage (but it's not)

seankooner commented 4 years ago

Anyone found any solution for this yet? Having the same issue with local state not being read during getDataFromTree

lifeiscontent commented 4 years ago

@seankooner post a reproduction of your issue.

akshatnitd commented 4 years ago

Meanwhile the issue can be fixed using getMarkupFromTree inplace of getDataFromTree. Reference thread - https://github.com/apollographql/react-apollo/issues/3251

ralexandr commented 4 years ago

Met same issue. Both getMarkupFromTree and getDataFromTree don't wait until all data is fetched. And, yes, I use await. But when I log Apollo's state returned by client.extract() and props of my Root component to console, Apollo-state is being logged first and after that I see log showing me that Root component has props.loading = true

ralexandr commented 4 years ago

Found solution for me: I removed old react-apollo package from my project’s deps and somehow that has resolved my issue