-
Notifications
You must be signed in to change notification settings - Fork 792
SSR not waiting for queries to resolve #3678
Comments
Seeing the same problem here. Downgrading @apollo/react-ssr to 3.1.2 seems to fix the issue. |
@abroadwin Doesn't seem todo the trick for me, looking at 3.1.2 nothing changed inside the |
Not sure what kind of react project you are using, but we had something of a similar situation using Nextjs. Downgrading next from 9.1.2 to 9.1.1 fixed the issue. |
I'm on NextJS as well but downgrading next to 9.1.1 did not fix for me, nor did taking react-ssr to 3.1.2 Same issue as above. |
Also with edit:
|
I'm seeing the same issue! If I check on the server side, the hooks are returning |
@theodoretliu yes seems like it. For now I just downgraded everything |
downgrading @apollo/react-hooks and @apollo/react-ssr to 3.0.0 fixed it for me. Using apollo-client@2.6.4 and next@9.1.4. |
Also noticing the same issue with 3.1.3 and 3.1.2, currently not able to update the package. worries me when there will be a security vulnerability and upgrading is necessary :/ for now 3.0.0 works..but kind of stuck there |
Would anyone here be able to provide a small runnable reproduction? |
https://github.com/theodoretliu/apollo-ssr-demo Here's a repro |
Thanks for working on a reproduction @theodoretliu. Your reproduction uses the |
Okay, thank you @hwillson. Correcting the versions actually did resolve the issue... See the repo https://github.com/theodoretliu/apollo-ssr-demo for a working set of versions. Still, I don't want to completely drop the issue because the documentation at the moment is very misleading. The combination of https://www.apollographql.com/docs/react/get-started/ and https://www.apollographql.com/docs/react/performance/server-side-rendering/ seem to indicate that the original combination I tried, where I installed the beta of I just feel like the documentation should never be in a state where following it all the way through would actually lead to incorrect behavior. |
https://github.com/fred8617/apollo-ssr-loop |
Oof just wasted my afternoon on this. The 3.0 docs point to react-ssr working with 3.0. Following - hopefully this is resolved soon |
Looks like the PR was merged, so this should hopefully be fixed on the next release |
Looks like SSR is working again! You folks rock. For anyone using getDataFromTree, make sure to update to |
I am also fighting with this issue for some time now - with the latest updates I also could fix the issue. |
@Linux249 I am experiencing the same issue on our primary code base for our site. We are using NextJS, with Apollo. The SSR render is not waiting for queries to resolve, and we are returning loading state. Please let me know how I can help, I've been digging for two days. |
Update: We are using the latest version of NextJS, using the "with-apollo" example located within the NextJS repository. Our queries are nested down into each component on the page, so we are using the NextJS AppTree in order to tell Apollo what data we need before the initial SSR Render. (Straight from the NextJS example). This works fine when I have one query, but the moment I add a second the first query breaks and only the second works. So we can get only one query to return with data for SSR, but not more than one. I'm not sure if this is an issue with the NextJS AppTree or Apollo, however we are desperate to find a solution as this is holding up a release for us. You heard it here will buy the beer for whoever can help fix this! |
@hwillson Are you still looking for a reproduction? I'd be happy to walk you through our issue if it helps. |
In a very simple custom SSR setup we are having the same problem. Queries do not resolve and finish loading. Anyone have a functioning repository example for this behavior working properly? Or only reproductions of non working functionality? @wesbos you said it’s working for you? |
I have it working in dev with @apollo/client@3.0.0-beta.32 + @apollo/react-ssr@4.0.0-beta.1 but my staging environment doesn't work, so hard to debug :( |
I am using the following:
Everything seems to work with this for now, and you will need to update later on but at least you can continue :D |
Still experiencing this issue with latest versions. Will build a reproduction that’s not next.js, unless someone has one to share. |
Updating to I am using:
|
Did you match up the mother dependencies as well? So everything too |
That solved it for me, big thanks! |
It's no use to me,I am using:
|
Something very similar happens with errors in getDataFromTree: |
Hopefully, @wesbos solution worked. Upgrading to |
Hope this helps someone else. Noticed the SSR issue in our app yesterday, viewing page source confirming it wasn't properly server rendering. Tried all the combinations of fixes that I could, none were working, including upgrading simply to the new 4.0.0-beta.1 react-ssr package. Then I randomly see this pull request merged about an hour ago as of writing: I upgraded my Can't guarantee it will work for anyone else, but worth a shot. |
This still doesn't fix for me unfortunately, using:
I can see that when viewing page source i have all the required cache apollo state:
but there is no generated HTML using this state, any clues why this would be happening? Something else i noticed is that when logging out the state in the returned WithApollo HOC:
the console log prints quite a few times, but apolloState is undefined 3/4 times initially then it it is populated? |
Beta 46 is unhappy with TypeScript so I couldn't test yet, but setting up a Next.js app with Apollo seems to lead to this issue. It behaves like |
Anything on this? I even clonned @wesbos repository and the SSR is not working actually. Nothing is broken but if you view source code, it just shows the Loading... state instead of the actual data. I tried many different versions, with/without Typescript but I always ended not having SSR... The same codebase but using Apollo 2, is working fine. |
Yeah it's broken again for me, unsure if it's next-with-apollo, react-apollo, or something else down the line. Sort of just sitting on it and hoping it gets fixed because I don't think there is anything wrong with my code. |
Can also confirm that Apollo 2 works perfectly fine, have reverted for now |
I found that if you don't check
ssr working (no loading check)
its weird that loading is second, i don't know if it expected or not, but on client during pages transition, useQuery works without any ssr, like normal react hook, with loading state and missing data during fetching. I found workaround for this by using apollo client directly and call the same query in |
Yeah I've run into situations where loading is true, but the data is also there. I think that is the core of this issue |
Any updates on this? I tried the code in the NextJS with-apollo example but no luck. I thought my database connection was just not there at first and I've wasted so much time on this before finding this thread 🙈 Even returning static data in my resolver doesn't result in SSR working, so it seems the problem really is @wesbos do you still have this problem? |
I personally switched to avoiding getDataFromTree completely and manually loading the SSR data within getInitialProps to warm the apollo cache. I also used a custom "import-blacklist": {
"severity": "error",
"options": [
{
"@apollo/client": ["useQuery"]
},
.... My custom useQuery.tsx looks like this: // tslint:disable-next-line:import-blacklist
import {
DocumentNode,
OperationVariables,
QueryHookOptions,
QueryResult,
useQuery as useApolloQuery,
} from '@apollo/client'
export function useQuery<TData = any, TVariables = OperationVariables>(
query: DocumentNode,
options: QueryHookOptions<TData, TVariables> = {}
): QueryResult<TData, TVariables> {
const opt = process.browser
? options
: {
ssr: false, // we no longer use the ssr from apollo!
...options,
}
return useApolloQuery<TData, TVariables>(query, opt)
} |
When running
@apollo/client
on the server the queries are not resolved before rendering static.When checking out
getMarkupFromTree
I noticed that the following code returns false:So non of the queries (using hooks) are ending up in
renderPromises
. Having hooked inapollo-logger
I did notice that the queries after the request get resolved!Intended outcome:
Complete the queries correctly for server side rendering.
Version
The text was updated successfully, but these errors were encountered: