react_on_rails 11.1.7 → 11.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f438e5ff9e6b2697d00f7232f748c3829b53099f5e048c68db7df913e7b0e778
4
- data.tar.gz: a285c7806a308fafb386dd1e9800a3650349a0d38ff09c03ec190ee3f795075f
3
+ metadata.gz: 060b6f22c90e0e79b6a60244c979aae68cf0aae3d3cc67b171e41a0040a1e229
4
+ data.tar.gz: 2667ab4972d468cb44cdc42bb6abc3c0536a4a8f3d6ac346df83b0d1249e12d6
5
5
  SHA512:
6
- metadata.gz: 153503d0d3913c8bdd74f818d5892da1d14aace2de687aa44b6539772dcef49d8555a4265f5ce56f531ea4fad428f882f0e66cf99e6149a7af1dd708e0c22201
7
- data.tar.gz: 6766c004cbd7358501179fadfffe8e5c50682be85b38bcc5c147e5c72f92a15f2a1afcf6cf36303fe2f9e45e2b22cf6cf38234d93b63da3cc7cf1ba2b309d271
6
+ metadata.gz: fb989846fd0e2c0af268850ead6c293d158e37ed87c12ced4dd09f21380ee8a5d2d5ef95116e264991ec928085f24198519a93b45a2e29f8ff68301c25c899b3
7
+ data.tar.gz: 6bda13faa6e598b3b85d13bdaa2842a53f6548aacf6ac9237612c061371f115ec967f87ff7030fbebe1c51af466949e98c6f02db56acfd6b79aa85057caaa5be
@@ -16,6 +16,11 @@ Changes since last non-beta release.
16
16
 
17
17
  *Please add entries here for your pull requests that are not yet released.*
18
18
 
19
+ ### [11.1.8] - 2018-10-14
20
+
21
+ #### Improved
22
+ - Improved tutorial and support for HMR when using `rails/webpacker` for Webpack configuration. [PR 1156](https://github.com/shakacode/react_on_rails/pull/1156) by [justin808](https://github.com/justin808).
23
+
19
24
  ### [11.1.7] - 2018-10-10
20
25
  #### Fixed
21
26
  - Fixed bug where intl parsing would fail when trying to parse integers or blank entries. by [sepehr500](https://github.com/sepehr500)
@@ -834,7 +839,8 @@ Best done with Object destructing:
834
839
  ##### Fixed
835
840
  - Fix several generator related issues.
836
841
 
837
- [Unreleased]: https://github.com/shakacode/react_on_rails/compare/11.1.7...master
842
+ [Unreleased]: https://github.com/shakacode/react_on_rails/compare/11.1.8...master
843
+ [11.1.8]: https://github.com/shakacode/react_on_rails/compare/11.1.7...11.1.8
838
844
  [11.1.7]: https://github.com/shakacode/react_on_rails/compare/11.1.6...11.1.7
839
845
  [11.1.6]: https://github.com/shakacode/react_on_rails/compare/11.1.5...11.1.6
840
846
  [11.1.5]: https://github.com/shakacode/react_on_rails/compare/11.1.4...11.1.5
data/README.md CHANGED
@@ -6,8 +6,6 @@ React on Rails integrates Rails with (server rendering of) Facebook's [React](ht
6
6
 
7
7
  Intersted in optimizing your webpack setup for React on Rails including code splitting with react-router v4, webpack v4, and react-loadable? [Contact me](mailto:justin@shakacode.com).
8
8
 
9
- ShakaCode is **[currently looking to hire](http://www.shakacode.com/about/#work-with-us)** like-minded developers that wish to work on our projects, including [Hawaii Chee](https://www.hawaiichee.com). Your main coding interview will be pairing with us on our open source! We're getting into [Reason](https://reasonml.github.io/)!
10
-
11
9
  # Intro
12
10
 
13
11
  ## Project Objective
@@ -16,8 +14,9 @@ To provide an opinionated and optimal framework for integrating Ruby on Rails wi
16
14
 
17
15
  ## Features and Why React on Rails?
18
16
 
19
- Given that rails/webpacker gem already provides basic React integration, why would you use "React on Rails"? Server rendering, often used for SEO and performance, is not offered by rails/webpacker.
17
+ Given that rails/webpacker gem already provides basic React integration, why would you use "React on Rails"?
20
18
 
19
+ 1. Server rendering, often used for SEO crawler indexing and UX performance, is not offered by rails/webpacker.
21
20
  1. The easy passing of props directly from your Rails view to your React components rather than having your Rails view load and then make a separate 1request to your API.
22
21
  1. [Redux](https://github.com/reactjs/redux) and [React Router](https://github.com/reactjs/react-router) integration.
23
22
  1. [Internationalization (I18n) and (localization)](https://github.com/shakacode/react_on_rails/blob/master/docs/basics/i18n.md)
@@ -37,6 +36,7 @@ React on Rails Pro provides Node server rendering and other performance enhancem
37
36
 
38
37
  ![2018-09-11_10-31-11](https://user-images.githubusercontent.com/1118459/45467845-5bcc7400-b6bd-11e8-91e1-e0cf806d4ea4.png)
39
38
 
39
+ * [HVMN Testimonial, Written by Paul Benigeri, October 12, 2018](./docs/testimonials/hvmn.md)
40
40
  * [HVMN’s 90% Reduction in Server Response Time from React on Rails Pro](https://blog.shakacode.com/hvmns-90-reduction-in-server-response-time-from-react-on-rails-pro-eb08226687db)
41
41
  * [Egghead React on Rails Pro Deployment Highlights](https://github.com/shakacode/react_on_rails/wiki/Egghead-React-on-Rails-Pro-Deployment-Highlights)
42
42
 
@@ -59,6 +59,10 @@ Please [email me (Justin Gordon), the creator of React on Rails](mailto:justin@s
59
59
 
60
60
  ## Testimonials for Hiring ShakaCode and our "Pro Support"
61
61
 
62
+ [HVMN Testimonial, Written by Paul Benigeri, October 12, 2018](./docs/testimonials/hvmn.md)
63
+
64
+ > The price we paid for the consultation + the React on Rails pro license has already been made back a couple of times from hosting fees alone. The entire process was super hands off, and our core team was able to focus on shipping new feature during that sprint.
65
+
62
66
  From Kyle Maune of Cooper Aerial, May 4, 2018
63
67
 
64
68
  ![image](https://user-images.githubusercontent.com/1118459/40891236-9b0b406e-671d-11e8-80ee-c026dbd1d5a2.png)
@@ -288,7 +292,7 @@ Here are some highly recommended next articles to read:
288
292
  1. [How React on Rails Works](./docs/basics/how-react-on-rails-works.md)
289
293
  1. [Recommended Project Structure](./docs/basics/recommended-project-structure.md)
290
294
  1. [Webpack Configuration](./docs/basics/webpack-configuration.md)
291
- 1. [View Helpers API](./docs/view-helpers-api.md)
295
+ 1. [View Helpers API](./docs/api/view-helpers-api.md)
292
296
  1. [Caching and Performance: React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki).
293
297
  1. [Deployment](docs/basics/deployment.md).
294
298
 
@@ -326,6 +330,9 @@ The following companies support this open source project, and ShakaCode uses the
326
330
 
327
331
  Aloha and best wishes from Justin and the ShakaCode team!
328
332
 
333
+ # Work with Us
334
+ ShakaCode is **[currently looking to hire](http://www.shakacode.com/about/#work-with-us)** like-minded, remote-first, developers that wish to work on our projects, including [Hawaii Chee](https://www.hawaiichee.com). Your main coding interview will be pairing with us on our open source! We're getting into [Reason](https://reasonml.github.io/)!
335
+
329
336
  # License
330
337
 
331
338
  The gem is available as open source under the terms of the [MIT License](LICENSE.md).
data/SUMMARY.md CHANGED
@@ -6,6 +6,8 @@
6
6
  + [React on Rails Basic Installation Tutorial](./docs/tutorial.md)
7
7
  + [Webpack Configuration](./docs/basics/webpack-configuration.md)
8
8
  + [How React on Rails Works](./docs/basics/how-react-on-rails-works.md)
9
+ + [Client vs. Server Rendering](./docs/basics/client-vs-server-rendering.md)
10
+ + [React Server Rendering](./docs/basics/react-server-rendering.md)
9
11
  + [Recommended Project Structure](./docs/basics/recommended-project-structure.md)
10
12
  + [Generator Functions and the RailsContext](docs/basics/generator-functions-and-railscontext.md)
11
13
  + [Caching and Performance: React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki).
@@ -50,7 +52,7 @@
50
52
  + [Setting up Hot Reloading during Rails Development, API docs](./docs/api/ruby-api-hot-reload-view-helpers.md)
51
53
  + [Developing with the Webpack Dev Server](./docs/additional-reading/webpack-dev-server.md)
52
54
  + [Webpack, the Asset Pipeline, and Using Assets w/ React](./docs/additional-reading/rails-assets-relative-paths.md)
53
- + [Hot Reloading of Assets For Rails Development](./docs/additional-reading/hot-reloading-rails-development.md)
55
+ + [Hot Reloading of Assets For Rails Development for Asset Pipeline](docs/additional-reading/hot-reloading-rails-development-asset-pipeline.md)
54
56
 
55
57
  ## **[CONTRIBUTING](CONTRIBUTING.md)**
56
58
  + [Generator Testing](./docs/contributor-info/generator-testing.md)
@@ -1,19 +1,9 @@
1
- # Live Reloading vs. Hot Reloading (aka HMR)
2
-
3
- The use of the [webpack-dev-server](https://webpack.js.org/configuration/dev-server/) provides "Live Reloading" by default. The difference between live and hot reloading is that live reloading will act similarly to hitting refresh in the browser. Hot reloading will attempt to preserve the state of any props.
4
-
5
- See the Webpack document [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/) for more details on the concepts of live vs. hot reloading.
6
-
7
- The remainder of this document discusses HMR.
8
-
9
- # Using the Webpacker Webpack setup
10
-
11
- If you are using the default Webpacker setup of running the dev server with `bin/webpack-dev-server`, see the [Webpacker Webpack Dev Server discussion of HMR](https://github.com/rails/webpacker/blob/master/docs/webpack-dev-server.md#hot-module-replacement).
1
+ *This document should only be referenced if you're **NOT** using the current technique of the rails/webpacker helpers to place your client-side assets in your `/public` directory.*
12
2
 
13
3
 
14
4
  # Hot Reloading of Assets For Rails Development
15
5
 
16
- _Note, this document is not yet updated for React on Rails v8+. See [PR #865](https://github.com/shakacode/react_on_rails/pull/865) for a detailed example of doing hot reloading using V8+ with Webpack v2. Any volunteers to update this page? See [#772](https://github.com/shakacode/react_on_rails/issues/772) and [#361](https://github.com/shakacode/react-webpack-rails-tutorial/issues/361)._
6
+ _See [PR #865](https://github.com/shakacode/react_on_rails/pull/865) for a detailed example of doing hot reloading using V8+ with Webpack v2. See [#772](https://github.com/shakacode/react_on_rails/issues/772) and [#361](https://github.com/shakacode/react-webpack-rails-tutorial/issues/361)._
17
7
 
18
8
  ------
19
9
 
@@ -44,7 +44,7 @@ More Details:
44
44
  Another good option is to create a simple test app per the [Tutorial](../tutorial.md).
45
45
 
46
46
  # Understanding the Organization of the Generated Client Code
47
- The generated client code follows our organization scheme. Each unique set of functionality, is given its own folder inside of `client/app/bundles`. This encourages for modularity of *domains*.
47
+ The generated client code follows our organization scheme. Each unique set of functionality, is given its own folder inside of `app/javascript/app/bundles`. Note, the recommended for bigger projects is `client/app/bundles`. This encourages for modularity of *domains*.
48
48
 
49
49
  Inside of the generated "HelloWorld" domain you will find the following folders:
50
50
 
@@ -1,5 +1,7 @@
1
1
  # React Server Rendering
2
2
 
3
+ See also [Client vs. Server Rendering](./client-vs-server-rendering.md)
4
+
3
5
  ## What is Server Rendering?
4
6
 
5
7
  Here's a [decent article to introduce you to server rendering](https://medium.freecodecamp.org/server-side-rendering-your-react-app-in-three-simple-steps-7a82b95db82e). Note, React on Rails takes care of calling the methods in [ReactDOMServer](https://reactjs.org/docs/react-dom-server.html).
@@ -8,7 +10,7 @@ During the Rails rendering of HTML per a browser request, the Rails server will
8
10
 
9
11
  The default JavaScript interpretter is [ExecJS](https://github.com/rails/execjs). If you want to maximize the perfomance of your server rendering, then you want to use React on Rails Pro which uses NodeJS to do the server rendering. See the [docs for React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki).
10
12
 
11
- See [this note](basics/how-react-on-rails-works.md#client-side-rendering-vs-server-side-rendering)
13
+ See [this note](./how-react-on-rails-works.md#client-side-rendering-vs-server-side-rendering)
12
14
 
13
15
 
14
16
  ## How do you do Server Rendering with React on Rails?
@@ -17,7 +17,7 @@ app/javascript:
17
17
  The problems with this structure and using rails/webpacker to configure Webpack for you:
18
18
 
19
19
  1. No support for different entry points for server rendering.
20
- 2. Webpacker adds an ex``tra layer of abstraction over Webpack, which you probably don't want.
20
+ 2. Webpacker adds an extra layer of abstraction over Webpack, which you probably don't want.
21
21
 
22
22
  This default rails/webpacker configuration is used for the generator because:
23
23
 
@@ -28,6 +28,29 @@ This default rails/webpacker configuration is used for the generator because:
28
28
 
29
29
  Thus, the generator structure and using rails/webpacker for Webpack configuration **is not recommended** for any commercial projects, especially those that will use server rendering. Instead, the recommended structure is shown in this example app: [github.com/shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) and described below.
30
30
 
31
+ ## Steps to convert from the generator defaults to use the recommended `/client` directory structure.
32
+
33
+ 1. Move the directory:
34
+
35
+ ```
36
+ mv app/javascript client
37
+ ```
38
+
39
+ 2. Edit your `/config/webpacker.yml` file. Change the `default/source_path`:
40
+
41
+ ```yml
42
+ source_path: client
43
+ ```
44
+
45
+ ## Moving node_modules from `/` to `/client` with a custom webpack setup.
46
+
47
+ `rails/webpacker` probably doesn't support having your main node_modules directory under `/client`, so only follow these steps if you want to use your own webpack configuration (which is highly recommended!).
48
+
49
+ 1. Move the `/package.json` to `/client/package.json`
50
+ 2. Create a `/pacage.json` that delegates to `/client/package.json`. See the example in [spec/dummy/package.json](../../spec/dummy/package.json).
51
+ 3. See the webpack configuration in [spec/dummy/client](../../spec/dummy/client) for a webpack configuration example.
52
+
53
+
31
54
  ## JavaScript Assets
32
55
  1. `/client`: All client side JavaScript goes under the `/client` directory. Place all the major domains of the client side app under client.
33
56
  1. `/client/app`: All application JavaScript. Note the adherence to the [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript#naming-conventions) where we name the files to correspond to exported Objects (PascalCase) or exported functions (camelCase). We don't use dashes or snake_case for JavaScript files, except for possibly some config files.
@@ -1,5 +1,16 @@
1
1
  # Webpack Configuration: custom setup for Webpack or rails/webpacker?
2
2
 
3
+ ## Webpack vs. rails/webpacker
4
+
5
+ [Webpack](https://webpack.js.org) is the JavaScript npm package that prepares all your client-side assets. The Rails asset pipeline used to be the preferable way to prepare client-side assets.
6
+
7
+ [rails/webpacker](https://github.com/rails/webpacker) is the Ruby gem that mainly gives us 2 things:
8
+
9
+ 1. View helpers for placing the Webpack bundles on your Rails views. React on Rails depends on these view helpers.
10
+ 2. A layer of abstraction on top of Webpack customization. This is great for demo projects, but most real world projects will want a customized version of Webpack.
11
+
12
+ # React on Rails
13
+
3
14
  Version 9 of React on Rails added support for the rails/webpacker view helpers so that Webpack produced assets would no longer pass through the Rails asset pipeline. As part of this change, React on Rails added a configuration option to support customization of the node_modules directory. This allowed React on Rails to support the rails/webpacker configuration of the Webpack configuration.
4
15
 
5
16
  A key decision in your use React on Rails is whether you go with the rails/webpacker default setup or the traditional React on Rails setup of putting all your client side files under the `/client` directory. While there are technically 2 independent choices involved, the directory structure and the mechanism of Webpack configuration, for simplicity sake we'll assume that these choices go together.
@@ -24,7 +24,7 @@ The default path: `public/webpack` can be loaded with webpackConfigLoader as sho
24
24
  1. Add `gem "webpacker"` to the Gemfile, run bundle. The gem provides the `stylesheet_pack_tag` and `javascript_pack_tag` helpers which is used to load the bundled assets to your layouts.[Dummy Example](../../spec/dummy/app/views/layouts/application.html.erb)
25
25
  1. Configure the `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [spec/dummy/config/initializers/react_on_rails.rb](../../spec/dummy/config/initializers/react_on_rails.rb) for a detailed example of configuration, including comments on the different values to configure.
26
26
  1. Configure your Procfiles per the example apps. These are at the root of your Rails installation.
27
- 1. Configure your top level JavaScript files for inclusion in your layout. You'll want a version that you use for static assets, and you want a file for any files in your setup that are not part of your webpack build. The reason for this is for use with hot-reloading. If you are not using hot reloading, then you only need to configure your `application.js` file to include your Webpack generated files. For more information on hot reloading, see [Hot Reloading of Assets For Rails Development](../additional-reading/hot-reloading-rails-development.md)
27
+ 1. Configure your top level JavaScript files for inclusion in your layout. You'll want a version that you use for static assets, and you want a file for any files in your setup that are not part of your webpack build. The reason for this is for use with hot-reloading. If you are not using hot reloading, then you only need to configure your `application.js` file to include your Webpack generated files. For more information on hot reloading, see [Hot Reloading of Assets For Rails Development](../additional-reading/hot-reloading-rails-development-asset-pipeline.md)
28
28
  1. If you are deploying to Heroku, see [heroku-deployment.md](/docs/additional-reading/heroku-deployment.md)
29
29
 
30
30
  If I missed anything, please submit a PR or file an issue.
@@ -0,0 +1,25 @@
1
+ # HVMN Testimonial, Written by Paul Benigeri, October 12, 2018
2
+
3
+ For some years, we used React on Rails for server-side rendering at [HVMN](https://hvmn.com). Our entire backend was already built in Rails, and we love React. As a content & e-commerce site, server-side rendering is critical, for UX performance and SEO crawler indexing.
4
+
5
+ During the 12 months leading up to our React on Rails Pro transition, our traffic grew 10x. Our team of 2 engineers was focused on shipping features, and we started to face performance issues. We had some fragment caching of our React server rending, but it didn’t work that well.
6
+
7
+ I discussed our growing pains with Justin, and as it turned out, ShakaCode just came out with React on Rails Pro and set it up on [egghead.io](https://egghead.io). The performance improvements were impressive, and Justin’s team was an ideal partner to help with the integration.
8
+
9
+ We decided to give it a shot. Over three weeks, the ShakaCode team helped us migrate to React on Rails Pro, set up Webpack v4, migrated our entire asset pipeline to Webpack v4.
10
+
11
+ Results were great. Our blog and product pages are 80-90% faster after that effort. The improved fragment caching was quick to set up and made a huge dent in our average server response times. We also observed an additional drop in response times when ShakaCode shipped the standalone Node server-side React renderer.
12
+
13
+ Working with ShakaCode was a pleasure. Justin is one of the smartest Rails architects I know, and his team was responsive and productive.
14
+
15
+ The price we paid for the consultation + the React on Rails pro license has already been made back a couple of times from hosting fees alone. The entire process was super hands off, and our core team was able to focus on shipping new feature during that sprint.
16
+
17
+ If you have any questions, please reach out.
18
+
19
+ Paul Benigeri
20
+ [paul@hvmn.com](mailto:paul@hvmn.com)
21
+ [LinkedIn](https://www.linkedin.com/in/benigeri/)
22
+
23
+ Related Article: [HVMN’s 90% Reduction in Server Response Time from React on Rails Pro](https://blog.shakacode.com/hvmns-90-reduction-in-server-response-time-from-react-on-rails-pro-eb08226687db)
24
+
25
+ [![image](https://user-images.githubusercontent.com/1118459/46911126-577abd00-ceee-11e8-86c6-6703ff80fc2f.png)](https://www.linkedin.com/in/benigeri/)
@@ -1,9 +1,16 @@
1
1
  # Testimonials
2
+ [HVMN Testimonial, Written by Paul Benigeri, October 12, 2018](./testimonials/hvmn.md)
3
+
4
+ > The price we paid for the consultation + the React on Rails pro license has already been made back a couple of times from hosting fees alone. The entire process was super hands off, and our core team was able to focus on shipping new feature during that sprint.
5
+
6
+ ---
2
7
 
3
8
  From Joel Hooks, Co-Founder, Chief Nerd at [egghead.io](https://egghead.io/), January 30, 2017:
4
9
 
5
10
  ![2017-01-30_11-33-59](https://cloud.githubusercontent.com/assets/1118459/22443635/b3549fb4-e6e3-11e6-8ea2-6f589dc93ed3.png)
6
11
 
12
+ ---
13
+
7
14
  From Kyle Maune of Cooper Aerial, May 4, 2018
8
15
 
9
16
  ![image](https://user-images.githubusercontent.com/1118459/40891236-9b0b406e-671d-11e8-80ee-c026dbd1d5a2.png)
@@ -47,9 +47,10 @@ cd <directory where you want to create your new Rails app>
47
47
  rails new test-react-on-rails --webpack=react
48
48
 
49
49
  cd test-react-on-rails
50
+ bundle
50
51
  ```
51
52
 
52
- Note: if you are installing React On Rails in an existing app or an app that uses Rails pre 5.1.3, you will need to run these two commands as well:
53
+ Note: if you are installing React On Rails in an existing app or an app that uses **Rails pre 5.1.3** (*not for Rails > 5.2*), you will need to run these two commands as well:
53
54
 
54
55
  ```
55
56
  bundle exec rails webpacker:install
@@ -59,7 +60,7 @@ bundle exec rails webpacker:install:react
59
60
  Add the **React On Rails** gem to your Gemfile:
60
61
 
61
62
  ```
62
- gem 'react_on_rails', '11.1.4' # prefer exact gem version to match npm version
63
+ gem 'react_on_rails', '11.1.7' # prefer exact gem version to match npm version
63
64
  ```
64
65
 
65
66
  Note: Latest released React On Rails version is considered stable. Please use the latest version to ensure you get all the security patches and the best support.
@@ -89,7 +90,7 @@ and then run server with
89
90
  foreman start -f Procfile.dev
90
91
  ```
91
92
 
92
- Visit http://localhost:3000/hello_world and see your **React On Rails** app running!
93
+ Visit [http://localhost:3000/hello_world](http://localhost:3000/hello_world) and see your **React On Rails** app running!
93
94
  Note, foreman defaults to PORT 5000 unless you set the value of PORT in your environment or in the Procfile.
94
95
 
95
96
  ### Custom IP & PORT setup (Cloud9 example)
@@ -115,7 +116,7 @@ It's super important to exclude certain directories from RubyMine or else it wil
115
116
  ### Create Your Heroku App
116
117
  *Assuming you can login to heroku.com and have logged into to your shell for heroku.*
117
118
 
118
- 1. Visit https://dashboard.heroku.com/new and create an app, say named `my-name-react-on-rails`:
119
+ 1. Visit [https://dashboard.heroku.com/new](https://dashboard.heroku.com/new) and create an app, say named `my-name-react-on-rails`:
119
120
 
120
121
  ![06](https://cloud.githubusercontent.com/assets/20628911/17465014/1f29bf3c-5cf4-11e6-869f-4215987ae854.png)
121
122
 
@@ -137,10 +138,11 @@ Set heroku to use multiple buildpacks:
137
138
  gem 'pg'
138
139
  ```
139
140
 
140
- ![07](https://cloud.githubusercontent.com/assets/20628911/17465015/1f2f4042-5cf4-11e6-8287-2fb077550809.png)
141
+ 2. Run `bundle`
141
142
 
143
+ ![07](https://cloud.githubusercontent.com/assets/20628911/17465015/1f2f4042-5cf4-11e6-8287-2fb077550809.png)
142
144
 
143
- 2. Replace your `database.yml` file with this (assuming your app name is "ror").
145
+ 3. Replace your `database.yml` file with this (assuming your app name is "ror").
144
146
 
145
147
  ```yml
146
148
  default: &default
@@ -185,11 +187,15 @@ root "hello_world#index"
185
187
 
186
188
  Next, configure your app for Puma, per the [instructions on Heroku](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server).
187
189
 
190
+ Create `/Procfile`. This is what Heroku uses to start your app.
191
+
188
192
  `Procfile`
189
193
  ```
190
194
  web: bundle exec puma -C config/puma.rb
191
195
  ```
192
196
 
197
+ Note, newer versions of Rails create this file automatically. However, the [docs on Heroku](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#config) have something a bit different, so please make it conform to those docs. As of 2018-10-13, the docs looked like this:
198
+
193
199
  `config/puma.rb`
194
200
  ```rb
195
201
  workers Integer(ENV['WEB_CONCURRENCY'] || 2)
@@ -212,9 +218,90 @@ end
212
218
  Then after all changes are done don't forget to commit them with git and finally you can push your app to Heroku!
213
219
 
214
220
  ```
215
- git add -A
216
- git commit -m "Latest changes"
221
+ git add -a
222
+ git commit -m "Changes for Heroku"
217
223
  git push heroku master
218
224
  ```
219
225
 
220
- Feedback is greatly appreciated! As are stars on github! If you want personalized help, don't hesitate to get in touch with us at [contact@shakacode.com](mailto:contact@shakacode.com).
226
+ Then run:
227
+
228
+ ```
229
+ heroku open
230
+ ```
231
+
232
+ and you will see your live app and you can share this URL with your friends. Congrats!
233
+
234
+
235
+ ## Turning on Server Rendering
236
+
237
+ You can turn on server rendering by simply changing the `prerender` option to `true`:
238
+
239
+ ```erb
240
+ <%= react_component("HelloWorld", props: @hello_world_props, prerender: true) %>
241
+ ```
242
+
243
+ Then push to Heroku:
244
+
245
+ ```
246
+ git add -a
247
+ git commit -m "Enable server rendering"
248
+ git push heroku master
249
+ ```
250
+
251
+ When you look at the source code for the page (right click, view source in Chrome), you can see the difference between non-server rendering, where your DIV containing your React looks like this:
252
+
253
+ ```html
254
+ <div id="HelloWorld-react-component-b7ae1dc6-396c-411d-886a-269633b3f604"></div>
255
+ ```
256
+
257
+ versus with server rendering:
258
+
259
+ ```html
260
+ <div id="HelloWorld-react-component-d846ce53-3b82-4c4a-8f32-ffc347c8444a"><div data-reactroot=""><h3>Hello, <!-- -->Stranger<!-- -->!</h3><hr/><form><label for="name">Say hello to:</label><input type="text" id="name" value="Stranger"/></form></div></div>
261
+ ```
262
+
263
+ For more details on server rendering, see:
264
+
265
+ + [Client vs. Server Rendering](./basics/client-vs-server-rendering.md)
266
+ + [React Server Rendering](./basics/react-server-rendering.md)
267
+
268
+ ## Moving from the Rails default `/app/javascript` to the recommended `/client` structure
269
+
270
+ ShakaCode recommends that you use `/client` for your client side app. This way a non-Rails, front-end developer can be at home just by opening up the `/client` directory.
271
+
272
+
273
+ 1. Move the directory:
274
+
275
+ ```
276
+ mv app/javascript client
277
+ ```
278
+
279
+ 2. Edit your `/config/webpacker.yml` file. Change the `default/source_path`:
280
+
281
+ ```yml
282
+ source_path: client
283
+ ```
284
+
285
+ ## Using HMR with the rails/webpacker setup
286
+
287
+ Start the app using `foreman start -f Procfile.dev-server`.
288
+
289
+ When you change a JSX file and save, the browser will automatically refresh!
290
+
291
+ So you get some basics from HMR with no code changes. If you want to go further, take a look at these links:
292
+
293
+ * https://github.com/rails/webpacker/blob/master/docs/webpack-dev-server.md
294
+ * https://webpack.js.org/configuration/dev-server/
295
+ * https://webpack.js.org/concepts/hot-module-replacement/
296
+ * https://gaearon.github.io/react-hot-loader/getstarted/
297
+ * https://github.com/gaearon/react-hot-loader
298
+
299
+ React on Rails will automatically handle disabling server rendering if there is only one bundle file created by the Webpack development server by rails/webpacker.
300
+
301
+ ## Conclusion
302
+
303
+ * Browse the docs either on the [gitbook](https://shakacode.gitbooks.io/react-on-rails/content/) or in the [docs directory on github](https://github.com/shakacode/react_on_rails/tree/master/docs)
304
+
305
+ Feedback is greatly appreciated! As are stars on github!
306
+
307
+ If you want personalized help, don't hesitate to get in touch with us at [contact@shakacode.com](mailto:contact@shakacode.com). We offer [React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki) and consulting so you can focus on your app and not on how to make Webpack plus Rails work optimally.
@@ -405,7 +405,9 @@ module ReactOnRails
405
405
 
406
406
  # Returns object with values that are NOT html_safe!
407
407
  def server_rendered_react_component(render_options)
408
- return { "html" => "", "consoleReplayScript" => "" } unless render_options.prerender
408
+ if !render_options.prerender || ReactOnRails::Utils.server_bundle_path_is_http?
409
+ return { "html" => "", "consoleReplayScript" => "" }
410
+ end
409
411
 
410
412
  react_component_name = render_options.react_component_name
411
413
  props = render_options.props
@@ -95,19 +95,21 @@ module ReactOnRails
95
95
  end
96
96
  end
97
97
 
98
+ def read_bundle_js_code
99
+ server_js_file = ReactOnRails::Utils.server_bundle_js_file_path
100
+ File.read(server_js_file)
101
+ rescue StandardError => e
102
+ msg = "You specified server rendering JS file: #{server_js_file}, but it cannot be "\
103
+ "read. You may set the server_bundle_js_file in your configuration to be \"\" to "\
104
+ "avoid this warning.\nError is: #{e}"
105
+ raise ReactOnRails::Error, msg
106
+ end
107
+
98
108
  def create_js_context
99
109
  return if ReactOnRails.configuration.server_bundle_js_file.blank?
100
110
 
101
- server_js_file = ReactOnRails::Utils.server_bundle_js_file_path
111
+ bundle_js_code = read_bundle_js_code
102
112
 
103
- begin
104
- bundle_js_code = File.read(server_js_file)
105
- rescue StandardError => e
106
- msg = "You specified server rendering JS file: #{server_js_file}, but it cannot be "\
107
- "read. You may set the server_bundle_js_file in your configuration to be \"\" to "\
108
- "avoid this warning.\nError is: #{e}"
109
- raise ReactOnRails::Error, msg
110
- end
111
113
  # rubocop:disable Layout/IndentHeredoc
112
114
  base_js_code = <<-JS
113
115
  #{console_polyfill}
@@ -118,7 +120,10 @@ module ReactOnRails
118
120
  file_name = "tmp/base_js_code.js"
119
121
  begin
120
122
  if ReactOnRails.configuration.trace
121
- Rails.logger.info { "[react_on_rails] Created JavaScript context with file #{server_js_file}" }
123
+ Rails.logger.info do
124
+ "[react_on_rails] Created JavaScript context with file "\
125
+ "#{ReactOnRails::Utils.server_bundle_js_file_path}"
126
+ end
122
127
  end
123
128
  ExecJS.compile(base_js_code)
124
129
  rescue StandardError => e
@@ -64,6 +64,10 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
64
64
  [stdout, stderr, status]
65
65
  end
66
66
 
67
+ def self.server_bundle_path_is_http?
68
+ server_bundle_js_file_path =~ %r{https?://}
69
+ end
70
+
67
71
  def self.server_bundle_js_file_path
68
72
  # Either:
69
73
  # 1. Using same bundle for both server and client, so server bundle will be hashed in manifest
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReactOnRails
4
- VERSION = "11.1.7".freeze
4
+ VERSION = "11.1.8".freeze
5
5
  end
@@ -4,6 +4,11 @@ module ReactOnRails
4
4
  ReactOnRails::Utils.gem_available?("webpacker")
5
5
  end
6
6
 
7
+ def self.dev_server_running?
8
+ return false unless using_webpacker?
9
+ Webpacker.dev_server.running?
10
+ end
11
+
7
12
  def self.bundle_js_file_path_from_webpacker(bundle_name)
8
13
  # Note Webpacker 3.4.3 manifest lookup is inside of the public_output_path
9
14
  # [2] (pry) ReactOnRails::WebpackerUtils: 0> Webpacker.manifest.lookup("app-bundle.js")
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "11.1.7",
3
+ "version": "11.1.8",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.1.7
4
+ version: 11.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-11 00:00:00.000000000 Z
11
+ date: 2018-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -361,7 +361,7 @@ files:
361
361
  - docs/additional-reading/elastic-beanstalk.md
362
362
  - docs/additional-reading/foreman-issues.md
363
363
  - docs/additional-reading/heroku-deployment.md
364
- - docs/additional-reading/hot-reloading-rails-development.md
364
+ - docs/additional-reading/hot-reloading-rails-development-asset-pipeline.md
365
365
  - docs/additional-reading/images.md
366
366
  - docs/additional-reading/node-dependencies-and-npm.md
367
367
  - docs/additional-reading/rails-assets-relative-paths.md
@@ -407,7 +407,8 @@ files:
407
407
  - docs/misc/code_of_conduct.md
408
408
  - docs/misc/doctrine.md
409
409
  - docs/misc/rails3.md
410
- - docs/testimonials.md
410
+ - docs/testimonials/hvmn.md
411
+ - docs/testimonials/testimonials.md
411
412
  - docs/tutorial.md
412
413
  - lib/generators/USAGE
413
414
  - lib/generators/react_on_rails/base_generator.rb