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

[fix] with-apollo: Cannot read property 'data' #3226

Merged
merged 2 commits into from
Nov 4, 2017

Conversation

JeromeFitz
Copy link
Contributor

When we create the initial serverState, we need to create the
eventual construct of the Apollo Data to reside within

Later in the constructor this allows for the initApollo to either
be generated from SSR, or to init from scratch.

Fixes

Cannot read property 'data' of undefined
TypeError: Cannot read property 'data' of undefined

When we create the initial serverState, we need to create the
 eventual construct of the Apollo Data to reside within

Later in the constructor this allows for the initApollo to either
 be generated from SSR, or to init from scratch.

Fixes
> Cannot read property 'data' of undefined
> TypeError: Cannot read property 'data' of undefined
@JeromeFitz
Copy link
Contributor Author

We could handle this in the constructor as well with a check, however, simply setting the empty object state seemed most straight forward.

If we want to keep serverState as {}, we can do the following in the constructor:

// Check if serverState is empty, and is an Object
this.apollo = (
  Object.keys(this.props.serverState).length === 0 &&
  this.props.serverState.constructor === Object
)
  ? initApollo() // No SSR render, initApollo
  : initApollo(this.props.serverState.apollo.data) // SSR Render, initApollo from serverState

No need to explicitly set `data` as empty.
This trims up 4 lines. 😀️
Copy link
Contributor

@adamsoffer adamsoffer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks!

@adamsoffer
Copy link
Contributor

This looks good to me. Lets merge 👍

@timneutkens timneutkens merged commit a450502 into vercel:canary Nov 4, 2017
@lock
Copy link

lock bot commented May 10, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018
@JeromeFitz JeromeFitz deleted the apollo-data-fix branch January 17, 2019 16:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants