-
Notifications
You must be signed in to change notification settings - Fork 787
State empty when SSR fails because of getDataFromTree throws #1403
Comments
Any updates on this? Should I send a PR fixing this after I find out the best solution? react-apollo/src/getDataFromTree.ts Line 178 in c95f7cb
This breaks entirely SSR |
What's even weirder, if you are using the next.js with-apollo example and upgrade to the latest preset, if the GraphQL server returns an error status code (like 400), the try catch does successfully catch the getDataFromTree successfully, but somehow the error is thrown later, after the try catch and the render, causing a crash :/ |
@flipxfx have you tried using |
I using |
Maybe use a |
Well now I can't reproduce it. I've updated quite a bit on our Apollo server and client since then so not sure what was happening. |
@gabriel-miranda did you find a solution to this? Currently the only solution I can see is to handle errors differently on the server vs client, e.g.
|
I get a similar issue when using
|
It is related to this one as well: |
|
@hwillson This is still an issue with the latest version.
Here is an example. We want to get the current user name and handle the case that the user is not logged in (which results in a GraphQl error): const CurrentUserQuery = gql`
query CurrentUser {
currentUser {
name
}
}
`
function useCurrentUser() {
return useQuery(CurrentUserQuery, {
ssr: true,
errorPolicy: 'none', // 'all' somewhat helps, at least the end result is the same, but I want the error object!
})
}
function ApolloTest(props) {
const { data, loading, error } = useCurrentUser()
if (error) {
return <BaseText>ERROR: {error.message}</BaseText>
}
return (
<BaseText>
{loading ? 'LOADING...' : (data && JSON.stringify(data)) || 'NO DATA'}
</BaseText>
)
} The server returns "LOADING...." while the client will show the error message after hydration. I think this is a duplicate of apollographql/apollo-client#3897 |
@hwillson This is still an issue, even with 4.0.0! I tested with Next.js 9.2.1:
|
any ideas? |
@hwillson we are having the same issue. When an SSR throws an error it will throw the error on our page level and have to restart the server. I see getDataFromTree is rewritten (but not catching) and we are using version 3 latest. how to proceed? The error will not be in the return, the app will just break When errorPolicy is set to all it will not throw it during treewalker, but error is not getting passed to component. Created reproduction on codesandbox in the issue mentioned below #3918 |
Same issue. We have authenticated queries that are allowed to fail which return |
Intended outcome:
SSR query fails and fills the field
loading
with:false
,error
with:<error>
and the<keys>
you wanted with their respective values. And doesn't run again on client side.Actual outcome:
SSR query fails and fills the field
loading
with:true
,error
with:undefined
and the<keys>
you wanted withundefined
.How to reproduce the issue:
You can reproduce it here: https://github.com/gabriel-miranda/chorus/tree/develop querying a post that doesnt exist, or doing a query that fails in any server with SSR (next.js example also).
This happens because when you do:
File reference:
https://github.com/gabriel-miranda/chorus/blob/develop/src/www/utils/withData.js
getDataFromTree throws an error and doesn't fill the apollo state needed.
Version
The text was updated successfully, but these errors were encountered: