-
Notifications
You must be signed in to change notification settings - Fork 754
Prerender error - TypeError: Cannot read property 'id' of undefined #197
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
Comments
This gets raised when prerendering raises a JavaScript error (https://github.com/reactjs/react-rails/blob/master/lib/react/renderer.rb#L52). It may be some issue related to the component code, do you mind sharing the component source? |
Great you pointed me in the right direction. So I'm defining current user in the top of my application like this,
Now the problem is that react_rails is loading just the components.js file which doesnt have the application page. I know this outside the scope of react-rails, but do you have any suggestions on defining a javascript currentUser from my current_user defined in rails? |
@jbhatab where do you use it? If you are using from within react, you can simply pass from |
Yeah but I'm not using it as a property like that. I'm using it as a global for things like permissions on every page. Maybe I could just set it up to always pass current_user on every page, but I think a global is doable. |
Cool. I think we can close this issue in that case. |
Yeah I'd say so. Any help is appreciated but this isn't a react-rails issue. |
@jbhatab yeah, some people have expressed interest in a similar feature. Right now, the JS instance that performs prerendering has no idea about application state or any data other than things passed to components as I can see the value of allowing the prerenderer to have access to some other arbitrary data, but personally it's not high on my list. You can see some related conversation in this discussion about isomorphic flux: |
Ahhh, perfect. Yeah this is all kinda getting figured out in general with all the new libraries and frameworks. I'll check that out. Thanks. |
I'm using jbuilder to serialize my data and just passing it to a really basic react component. I'm really at a loss of what is happening because nothing is undefined and it is getting the right serialized data. This is the error I'm getting.
Encountered error "TypeError: Cannot read property 'id' of undefined" when prerendering ProjectIndexPage with {"projects":[{"id":1,"name":"aweseom","following":false}]}
And here are all the relevant files.
app/views/projects/index.html.slim
app/views/projects/index.json.jbuilder
app/assets/javascripts/application.js
app/assets/javascripts/components.js
The text was updated successfully, but these errors were encountered: