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

[Q] Server side rendering #119

Closed
woniesong92 opened this issue Feb 26, 2017 · 23 comments
Closed

[Q] Server side rendering #119

woniesong92 opened this issue Feb 26, 2017 · 23 comments

Comments

@woniesong92
Copy link

This is a question, not an issue with the project -- feel free to close it if it shouldn't be here.

In one of my recent projects, I gave up using Rails views completely and used React components instead. The Rails router takes care of the API endpoints and the react router takes care of the views. The controllers would serve the resources in JSON to the react views. One problem I couldn't solve with this setup was server-side rendering.

I think a lot of people will try what I did when webpacker becomes more mature. Do you have an idea about how to solve server-side-rendering problem when people use Rails as an API backend and use JS to render the views?

@ytbryan
Copy link
Contributor

ytbryan commented Feb 26, 2017

@woniesong92
Copy link
Author

@ytbryan Unfortunately no 😢 . I tried react-rails but it's too tightly coupled with Rails' asset pipeline and isn't intended to work well with other react libraries/tools (e.g. Redux, HMR).

@renchap
Copy link
Contributor

renchap commented Feb 26, 2017

We are working on https://github.com/renchap/webpacker-react to provide Webpacker+React integration. Server-side rendering is not done yet, but should be soon.

@woniesong92
Copy link
Author

@renchap would that be a part of this gem as well?

@renchap
Copy link
Contributor

renchap commented Feb 26, 2017

Yes. I outlined how it would work here : renchap/webpacker-react#3

@woniesong92
Copy link
Author

@renchap oh! So webpacker-react will be merged to rails/webpacker, and rails/webpacker will be merged to rails?

@woniesong92
Copy link
Author

Great work by the way 😄

@renchap
Copy link
Contributor

renchap commented Feb 26, 2017

I meant that server-rendering would be a part of webpacker-react, which will stay as a separate gem form Webpacker.
I dont think Webpacker will be merged into the main rails repository (for example Sprockets/sprockets-rails are still separate repos), but it will be supported out of the box by Rails 5.1.

@justin808
Copy link
Contributor

@woniesong92 @ytbryan Take a look at

https://github.com/shakacode/react_on_rails

I'm going to take a look today at having it support webpacker. We've got many live projects using server rendering with React and Wepback.

Let me know if you want a Slack invite a justin@shakacode.com. I'm happy to help. We've got a vibrant community working on this topic and over 2700 stars, and, according to nmpjs.com, over 112K downloads in the last month.

@gauravtiwari
Copy link
Member

@woniesong92 Does it work out? Please consider closing this issue. Thank you everyone for your answers.

@woniesong92
Copy link
Author

@gauravtiwari thanks for the answers!

@woniesong92
Copy link
Author

@renchap Hey, thanks for the help before.
Do you know the best practice for server side rendering now that Rails 5.1 is shipped with webpacker? I think using react-rails for server side rendering might be a good solution, but wanted to know if there was a better way.

@justin808
Copy link
Contributor

@woniesong92 Please take a look a React on Rails. Many companies use it, including server-side rendering. Projects and Kudos.

@snuggs
Copy link

snuggs commented Jun 13, 2017

I can concur with @justin808. Awesome project. Looking forward to his presentation at NYC.rb ;-) <3

@justin808
Copy link
Contributor

@deesx I don't understand your comment in regards to procfiles. You don't need any procfiles. Procfiles are simply a way to easily start up multiple processes.

@ForkInSpace
Copy link

Hey guys, any progress towards server side rendering feature? or is there an alternative to use (which won't require too much time to migrate to?

@benbonnet
Copy link

benbonnet commented Jun 28, 2018

@justin808 meant by that; it is confusing to see it systematically promoted when the 'server side rendering' topic pops up

@inkhrt
Copy link

inkhrt commented Jul 3, 2018 via email

@justin808
Copy link
Contributor

For the record React on Rails thoroughly supports React Serve-Side Rendering, along with react-rails, which is, AFAIK, the only other library that supports this. Both of these libraries leverage rails/webpacker for the view helpers and can use the default Webpack configuration IF you want the same configuration for both server and client side. However, that would be unusual as it's common to use techniques like code-splitting on the client, which makes no sense for server rendering.

@justin808
Copy link
Contributor

I just wrote an article on using the pre-release of v4 with React on Rails, including server-side-rendering and concurrent use of the webpack-dev-server.

Easy React Server Rendering with rails/webpacker v4 and React on Rails

I included a few github repo examples.

@dachinat
Copy link

Hi, can I use Rails 5.2.1 with webpack:react and server-side rendering today?
Thanks.

@justin808
Copy link
Contributor

@dachinat you need to use either https://github.com/shakacode/react_on_rails or https://github.com/reactjs/react-rails/. Both can get the job done. Besides the docs, check out the CHANGELOGs to get a sense of activity in the projects.

@dachinat
Copy link

dachinat commented Nov 6, 2018

@justin808 very nice, 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

10 participants