Apollo-client: getDataFromTree hangs and is never resolved during SSR

Created on 4 Jun 2020  路  13Comments  路  Source: apollographql/apollo-client

Intended outcome:
getDataFromTree should resolve or reject.

Actual outcome:
It hangs and never finishes.

* possible solution *
https://github.com/apollographql/apollo-client/blob/c76804eea2afcd3df4e01d5a8db3ae2c4c553aee/src/react/data/QueryData.ts#L294
When I changed this.isMounted = true during SSR, it works as expected.
So, during SSR isMounted never becomes true.

How to reproduce the issue:

Versions
System:
OS: macOS 10.15.5
Binaries:
Node: 12.18.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.5 - ~/.npm-global/bin/npm
Browsers:
Chrome: 83.0.4103.97
Firefox: 60.0.2
Safari: 13.1.1

馃摕 regression

Most helpful comment

I'm still seeing this issue on 3.0rc.1 as well.

All 13 comments

This merge seems to be the cause. https://github.com/apollographql/apollo-client/pull/6216
Is there tests to avoid these unintentional bugs?

@joonhocho Can you try @apollo/[email protected], which includes #6388?

I think the reason testing didn't catch this is that getDataFromTree lives in @apollo/react-ssr rather than this repository, and I merged #6216 without running those tests. So there are tests, and this regression would have been caught one way or another, but it was my mistake not to run the React Apollo tests before the rc.0 release. Sorry about that!

I'm still seeing this issue on 3.0rc.1 as well.

I'm experiencing the same issue with 3.0.0-rc.1. I effectively have the same code as in the Next.js Apollo example:

https://github.com/vercel/next.js/blob/master/examples/with-apollo/lib/apollo.js

Thanks for the updates. Since my attempt to salvage #6216 was not successful, I think it makes the most sense to revert it (along with #6388) for now: #6395.

Heads up: @apollo/[email protected] is out now, including just #6395.

getDataFromTree has stopped hanging for me now that I've upgraded to @apollo/[email protected], however I've a test for my SSR requests that's failing. When I view the page source by navigating to view-source:http://localhost:3000/, my components that use apollo are all in a loading state.

This might be a problem somewhere in my code, the next.js withApollo example has a lot going on. If worth checking in your setup if SSR is still working as expected.

This looks to be a problem with @apollo/[email protected], and not my code (I had suspected it was my code). I've just taken the latest next.js with-apollo example app, and tried upgrading it to use rc.2. You can see the changes I made here: https://github.com/lyonsv/with-apollo-app.

Before making my changes, I could view page source and see the correct markup generated by successfully loading graphql data server side. After making my changes, the server generated markup indicates a loading state.

The new next.js with-apollo example is substantially different to the code in my application where I am experiencing the same problem. My code looked more like their old example: https://github.com/vercel/next.js/blob/master/examples/with-apollo/lib/apollo.js.

This may require a new issue to track. You've definitely stopped getDataFromTree from hanging - my client-side app was completely failing to load before upgrading to rc.2

@lyonsv, we've seen the behavior you describe (data is fetched during the SSR, but the rendering stops after the first loading state is encountered) all throughout the 3.0 alpha cycle, so @apollo/[email protected] is simply reverting to what was happening earlier. It's unclear to me if it's an issue in @apollo/client or in @apollo/react-ssr (we're using 4.0.0-beta.1).

@dhalbrook are you sure it's been a problem for the whole alpha cycle?

On the repo I've used to produce a test example, it seems to break between beta.7 and beta.8. My last two commits will show the source including a loading when using beta.8, and returning the expected markup with GraphQL supplied data in beta.7. A quick sample of a few versions before 7 suggest this is a regression in introduced between 7 and 8. Glancing at the commits between the two versions, there's a lot going on and there's nothing obvious to me that could be the cause.

https://github.com/lyonsv/with-apollo-app

If there isn't a test to check if SSR is still working, I could try and submit one. The test suite which I have has a high level Cypress test and a high level test on my server...check the response from a request for the expected data.

The commits where the the problem occurs should be identifiable below:

https://github.com/apollographql/apollo-client/commits/ab0bbe2f5b06465c9c54de8c633e119e21881504

I went back and checked our package history and realized I misspoke. Turns out we switched to client 3.0 at @beta 41, so much later than I thought. Thanks for digging into the SSR issue @lyonsv , it's been on my list to do so for a while now.

I've created a new issue for my problem with SSR, as the hanging getDataFromTree problem has been resolved.

https://github.com/apollographql/apollo-client/issues/6422

Since the remaining issue here has been opened in https://github.com/apollographql/apollo-client/issues/6422, I'll close this off. Thanks!

Was this page helpful?
0 / 5 - 0 ratings