-
Notifications
You must be signed in to change notification settings - Fork 759
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
Server-side rendering is not working with sprockets-rails 3.0 #443
Comments
OK, there is an opened pull-request https://github.com/reactjs/react-rails/pull/430/files |
Could you give that branch a try? Let me know if it works for you -- it looks good to me but I'd like a second opinion before I merge it! |
I need this too :( I will test your PR very soon @rmosolgo ! Thanks for your work!! |
This would be super helpful! |
@rmosolgo |
It fails at this line https://github.com/reactjs/react-rails/pull/430/files#diff-543f6fa05678c006b8d4baa5cd4b517cR13, not being able to find |
+1 |
1 similar comment
+1 |
Could you try react-rails 1.6.0? It includes #430 which was my first try at fixing this |
I can confirm that I have this issue in production with 1.6.0 when server-side rendering is used.
|
Ok, thanks, let me try to track that down! |
Ohh strange. When it creates the manifest, the manifest has I found a workaround:
This way, it bundles react-server into server_rendering.js, it doesn't look it up when you try to render a page! I'll look for a proper fix tonight or tomorrow! |
We didn't want the react-server code to end up in the components.js since that's delivered to browser clients. So we created a components-server.js file containing:
And then added that components-server.js file to the server_rendering_options:
This seemed to fix the prerendering asset location error above. However, we then were getting an error because of an additional sprockets 3 incompatibility. PR for that is here #478 |
It seems that #471 fixes this issue. The only thing that needs to be done is to add server_rendering.js to the |
Maybe i should add that to |
Sounds good) |
i'm using any ideas? |
This patch isn't merged yet because it'll be a breaking change. Did you try the workaround described here? #443 (comment) |
Updates: ok ive tried the above workaround but it doesnt seem to work. I've also tried some workaround on my own, ie: http://cl.ly/2c3O3s343Y3k but to no avail too. I've also upgraded to |
Can you elaborate? For example, did you get an error? What was the message & stack trace? Also, did you restart your development server after changing the configurations? |
The workaround didn't help me either.
|
Weird! It shouldn't even be looking for config.react.server_renderer_options = {
files: ["server_rendering.js"], # files to load for prerendering
} 😿 |
(Usually, it's the default provided here: https://github.com/reactjs/react-rails/blob/master/lib/react/server_rendering/sprockets_renderer.rb#L18) |
just to be clear: I put the |
Confirming that the workaround works with 1.7.1. I tried to get a component that uses moment.js in its
Anything else I need to do to get that to work? |
hmm did u put //= require moment above your component definition? some code samples might be useful |
Does server_rendering.js go in We're getting...
|
@krazyjakee did you add server_rendering.js into the asset precompile list? |
@alcedo yes, it is definitely there. |
my server_rendering.js goes into /assets/javascripts/server_rendering.js and this is the content of it, if its of any help.
|
@alcedo mine was...
I'll tweak it and get back to you. Thanks! |
no problem. and i think you probably wont need react_ujs, since its only used on client side. |
Did the workaround! But now I get the same error with
Rails 4.2.6 |
To confirm, did you add Rails.application.config.assets.precompile += %w(server_rendering.js) ? |
Yes! Did all the steps you provided! I'm still trying to find out! |
woah, how strange?! did anything else change in your app at that time? |
I'm trying to figure out! Looking through the commits, updated some code and added only a few gems, but nothing related to React itself. But I don't believe these changes are related with this rendering issue. |
@rafaelv90 I'm experiencing the same thing, worked fine in production, still works in dev but today stopped working in production. |
was it after a redeploy? or, it just started 💥ing while running? |
@rmosolgo after redeploy. I have 2 production servers, one I use as staging. When I pushed up to staging it broke today. When I push the existing working production server code to staging (an exact production replica) it starts throwing the "was it precompiled" error. |
Is the diff for that redeploy small enough to list the changes? For example:
|
@rmosolgo The production code mirrored on staging worked, my mistake was viewing the log, it was a process of the prior build, learned something new about EY. I also found that when deploying on EngineYard the assets won't re-precomplie if the assets.rb is changed, only if the assets .js/.css are changed, or its in the EY config to always precomplie. Solution that worked for me Unfortunately I was not able to locate the differences that suddenly required the react-server.js components.js to be listed in the precomplie, I did check the gemlock files of both codebases and they are identical. |
Thanks for sharing your findings!! |
I can confirm that I only had to add |
Guys, in my scenario I use separated manifest files for loading dependencies and react components for main interface and admin interface. My files are divided as following: application.js: //= require jquery
//= require jquery_ujs
//= require bootstrap
//= require maskedinput
//= require jquery.fancybox
//= require getstream
//= require react
//= require react_ujs
//= require react-rails-hot-loader
//= require components server_rendering_components.js: //= require react
//= require react-server
//= require components components.js: //= require accounting.min
//= require moment-with-locales.min
//= require autosuggest
//= require_tree ./react
moment.locale('pt-br'); admin.js: //= require react
//= require react_ujs
//= require react-rails-hot-loader
//= require admin_components server_rendering_admin_components.js: //= require react
//= require react-server
//= require admin_components admin_components.js: //= require_tree ./admin-react config/environments/{development.rb,production.rb}" config.react.server_renderer_options = {
files: ['server_rendering_components.js, server_rendering_admin_components.js']
} config/initializers/assets.rb: Rails.application.config.assets.precompile += %w( admin.js admin.css server_rendering_components.js components.js server_rendering_admin_components.js admin_components.js ) I just keep getting this error:
What I'm doing wrong? |
Nevermind guys, I just fix the files object to correction: Instead of: config.react.server_renderer_options = {
files: ['server_rendering_components.js, server_rendering_admin_components.js']
} Corrected for this: config.react.server_renderer_options = {
files: ['server_rendering_components.js', 'server_rendering_admin_components.js']
} |
Sounds like we have a couple of options here. Soon I'll merge #471 and remove the confusing defaults. Thanks for sharing your solutions! |
Fixes run time bug where react components won't load with 500 error Solution taken from: reactjs/react-rails#443 (comment)
In sprockets-rails 3.0
Rails.application.assets
is disabled whenconfig.assets.compile=false
(rails/sprockets-rails#220).And
React::ServerRendering::SprocketsRenderer
is failing on production environment at this line, withundefined method '[]' for nil:NilClass
The text was updated successfully, but these errors were encountered: