Skip to content

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