Skip to content
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

initialState is undefined despite passing getDataFromTree #184

Open
bschwartz757 opened this issue Jun 14, 2022 · 0 comments
Open

initialState is undefined despite passing getDataFromTree #184

bschwartz757 opened this issue Jun 14, 2022 · 0 comments

Comments

@bschwartz757
Copy link

Hello,

I'm trying to get this package to work with an existing application that we're trying to upgrade to Next.js 12. Our application was built using getDataFromTree and refactoring everything to use the new getServerSideProps approach is going to be an enormous lift for us.

I've followed along with the example here https://github.com/lfades/next-with-apollo#using-_app as best I can but initialState is coming up as undefined inside the withApollo() function. I am passing getDataFromTree from @apollo/client/react/ssr:

export default withApollo (({initialState}) => {
// App-specific authentication logic, setting up authMiddleware using ApolloLink and HttpLink
  return new ApolloClient({
    cache: new InMemoryCache({
      dataIdFromObject: object => object.sku || object.id
    }).restore(initialState || {}),
    link: concat(authMiddleware, httpLink)
  }),
},
{  getDataFromTree})(AppWithRedux)

A couple of additional factors:

  • The existing AppWithRedux is a class component with a getInitialProps static method (I am calling App.getInitialProps like the Next.js docs show, that seems to be working).
  • We (obviously) have a custom _app. We also have a custom _document, I'm wondering if we need to do anything additional due to using a custom document? We might be facing the same issue as this user because we use Styled Components so there is a bunch of stylesheet and other third-party code setup in there.

Any help would be appreciated, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant