react_on_rails 11.1.7 → 11.3.1.beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc +8 -2
  3. data/.prettierignore +1 -0
  4. data/.prettierrc +20 -0
  5. data/.release-it.json +3 -0
  6. data/.travis.yml +10 -9
  7. data/CHANGELOG.md +60 -3
  8. data/CONTRIBUTING.md +2 -10
  9. data/Gemfile +1 -2
  10. data/Gemfile.rails32 +0 -1
  11. data/README.md +30 -14
  12. data/SUMMARY.md +6 -2
  13. data/docs/additional-reading/{hot-reloading-rails-development.md → hot-reloading-rails-development-asset-pipeline.md} +2 -12
  14. data/docs/additional-reading/images.md +1 -1
  15. data/docs/additional-reading/rails_view_rendering_from_inline_javascript.md +2 -1
  16. data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +10 -0
  17. data/docs/api/view-helpers-api.md +12 -8
  18. data/docs/basics/configuration.md +4 -4
  19. data/docs/basics/generator-details.md +1 -1
  20. data/docs/basics/minitest-configuration.md +31 -0
  21. data/docs/basics/react-server-rendering.md +3 -1
  22. data/docs/basics/recommended-project-structure.md +24 -1
  23. data/docs/basics/rspec-configuration.md +2 -2
  24. data/docs/basics/upgrading-react-on-rails.md +11 -1
  25. data/docs/basics/webpack-configuration.md +11 -0
  26. data/docs/misc-pending/code-splitting.md +2 -2
  27. data/docs/misc-pending/manual-installation-overview.md +1 -1
  28. data/docs/testimonials/hvmn.md +25 -0
  29. data/docs/testimonials/resortpass.md +13 -0
  30. data/docs/testimonials/testimonials.md +28 -0
  31. data/docs/tutorial.md +123 -11
  32. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -0
  33. data/lib/generators/react_on_rails/install_generator.rb +2 -0
  34. data/lib/react_on_rails.rb +1 -0
  35. data/lib/react_on_rails/assets_precompile.rb +3 -0
  36. data/lib/react_on_rails/configuration.rb +2 -1
  37. data/lib/react_on_rails/git_utils.rb +2 -0
  38. data/lib/react_on_rails/helper.rb +71 -70
  39. data/lib/react_on_rails/json_output.rb +1 -1
  40. data/lib/react_on_rails/locales_to_js.rb +2 -0
  41. data/lib/react_on_rails/react_component/render_options.rb +4 -0
  42. data/lib/react_on_rails/server_rendering_js_code.rb +42 -0
  43. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +44 -14
  44. data/lib/react_on_rails/utils.rb +5 -1
  45. data/lib/react_on_rails/version.rb +1 -1
  46. data/lib/react_on_rails/version_checker.rb +4 -1
  47. data/lib/react_on_rails/webpacker_utils.rb +9 -1
  48. data/package-scripts.yml +46 -0
  49. data/package.json +24 -15
  50. data/rakelib/release.rake +3 -2
  51. data/react_on_rails.gemspec +1 -1
  52. data/webpackConfigLoader.js +2 -2
  53. data/yarn.lock +4431 -1689
  54. metadata +18 -10
  55. data/docs/testimonials.md +0 -11
@@ -0,0 +1,10 @@
1
+ # Upgrading rails/webpacker v3.5 to v4
2
+
3
+ The following steps can be followed to update a Webpacker v3.5 app to v4.
4
+
5
+ 1. Update the gem `webpacker` and the package `@rails/webpacker`
6
+ 1. Merge changes from the new default [.babelrc](../lib/install/config/.babelrc) to your `/.babelrc`. If you are using React, you need to add `"@babel/preset-react"`, to the list of `presets`.
7
+ 1. Copy the file [.browserslistrc](../lib/install/config/.browserslistrc) to `/`.
8
+ 1. Merge any differences between [config/webpacker.yml](../lib/install/config/webpacker.yml) and your `/config/webpacker.yml`.
9
+
10
+ Here is an [example commit of these changes](https://github.com/shakacode/react_on_rails-tutorial-v11/pull/1/files).
@@ -10,21 +10,25 @@ Once the bundled files have been generated in your `app/assets/webpack` folder a
10
10
  ```ruby
11
11
  react_component(component_name,
12
12
  props: {},
13
- prerender: nil,
14
- trace: nil,
15
- replay_console: nil,
16
- raise_on_prerender_error: nil,
17
- id: nil,
13
+ prerender: nil)
18
14
  html_options: {})
19
15
  ```
20
16
 
17
+ Uncommonly used options:
18
+ ```
19
+ trace: nil,
20
+ replay_console: nil,
21
+ raise_on_prerender_error: nil,
22
+ id: nil,
23
+ ```
24
+
21
25
  - **component_name:** Can be a React component, created using an ES6 class or a generator function that returns a React component (or, only on the server side, an object with shape { redirectLocation, error, renderedHtml }), or a "renderer function" that manually renders a React component to the dom (client side only).
22
26
  All options except `props, id, html_options` will inherit from your `react_on_rails.rb` initializer, as described [here](../basics/configuration.md).
23
27
  - **general options:**
24
28
  - **props:** Ruby Hash which contains the properties to pass to the react object, or a JSON string. If you pass a string, we'll escape it for you.
25
29
  - **prerender:** enable server-side rendering of a component. Set to false when debugging!
26
30
  - **id:** Id for the div, will be used to attach the React component. This will get assigned automatically if you do not provide an id. Must be unique.
27
- - **html_options:** Any other HTML options get placed on the added div for the component. For example, you can set a class (or inline style) on the outer div so that it behaves like a span, with the styling of `display:inline-block`.
31
+ - **html_options:** Any other HTML options get placed on the added div for the component. For example, you can set a class (or inline style) on the outer div so that it behaves like a span, with the styling of `display:inline-block`. You may also use an option of `tag: "span"` to replace the use of the default DIV tag to be a SPAN tag.
28
32
  - **trace:** set to true to print additional debugging information in the browser. Defaults to true for development, off otherwise. Only on the **client side** will you will see the `railsContext` and your props.
29
33
  - **random_dom_id:** True to automatically generate random dom ids when using multiple instances of the same React component on one Rails view.
30
34
  - **options if prerender (server rendering) is true:**
@@ -41,7 +45,7 @@ adding meta-tags to a page. It is exactly like react_component except for the fo
41
45
 
42
46
  1. `prerender: true` is automatically added to options, as this method doesn't make sense for
43
47
  client only rendering.
44
- 2. Your JavaScript for server rendering must return an Object for the key `server_rendered_html`.
48
+ 2. Your JavaScript generator function for server rendering must return an Object rather than a React Component.
45
49
  3. Your view code must expect an object and not a string.
46
50
 
47
51
  Here is an example of ERB view code:
@@ -89,7 +93,7 @@ end %>
89
93
 
90
94
  ### rails_context
91
95
 
92
- You can call `rails_context(server_side: true | false)` from your controller or view to see what values are are in the Rails Context. Pass true or false depending on whether you want to see the server side or the client side rails_context.
96
+ You can call `rails_context` or `rails_context(server_side: true|false)` from your controller or view to see what values are are in the Rails Context. Pass true or false depending on whether you want to see the server side or the client side rails_context. Typically, for computing cache keys, you should leave server_side as the default true. When calling this from a controller method, use `helpers.rails_context`.
93
97
 
94
98
  ------------
95
99
 
@@ -124,7 +124,6 @@ ReactOnRails.configure do |config|
124
124
  # While you may configure this to be the same as your client bundle file, this file is typically
125
125
  # different. Note, be sure to include the exact file name with the ".js" if you are not hashing this file.
126
126
  # If you are hashing this file (supposing you are using the same file for client rendering), then
127
- #
128
127
  # you should include a name that matches your bundle name in your webpack config.
129
128
  config.server_bundle_js_file = "server-bundle.js"
130
129
 
@@ -145,10 +144,11 @@ ReactOnRails.configure do |config|
145
144
  #
146
145
  config.logging_on_server = true
147
146
 
148
- # Default is to false to NOT raise exception on server if the JS code throws.
149
- # Reason is that it's easier to debug this when you get the error over to the client.
147
+ # Default is true only for development? to raise exception on server if the JS code throws for
148
+ # server rendering. The reason is that the server logs will show the error and force you to fix
149
+ # any server rendering issues immediately during development.
150
150
  #
151
- config.raise_on_prerender_error = false
151
+ config.raise_on_prerender_error = Rails.env.development?
152
152
 
153
153
  ################################################################################
154
154
  # Server Renderer Configuration for ExecJS
@@ -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
 
@@ -0,0 +1,31 @@
1
+ # Minitest Configuration
2
+
3
+ The setup for minitest is the same as for rspec with the following difference.
4
+
5
+ Rather than calling `ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)`, instead you will do something like this:
6
+
7
+ ```ruby
8
+ class ActiveSupport::TestCase
9
+ setup do
10
+ ReactOnRails::TestHelper.ensure_assets_compiled
11
+ end
12
+ end
13
+ ```
14
+
15
+
16
+ Or maybe something like this, from the [minitest docs](https://github.com/seattlerb/minitest/blob/master/lib/minitest/test.rb#L119):
17
+
18
+ ```ruby
19
+ module MyMinitestPlugin
20
+ def before_setup
21
+ super
22
+ ReactOnRails::TestHelper.ensure_assets_compiled
23
+ end
24
+ end
25
+
26
+ class MiniTest::Test
27
+ include MyMinitestPlugin
28
+ end
29
+ ```
30
+
31
+
@@ -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 `/package.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,4 +1,6 @@
1
1
  # RSpec Configuration
2
+ _Click [here for minitest](./minitest-configuration.md)_
3
+
2
4
  Because you will probably want to run RSpec tests that rely on compiled webpack assets (typically, your integration/feature specs where `js: true`), you will want to ensure you don't accidentally run tests on missing or stale webpack assets. If you did use stale Webpack assets, you will get invalid test results as your tests do not use the very latest JavaScript code.
3
5
 
4
6
  ReactOnRails provides a helper method called `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`. Call this method from inside of the `RSpec.configure` block in your `spec/rails_helper.rb` file, passing the config as an argument. See file [lib/react_on_rails/test_helper.rb](../../lib/react_on_rails/test_helper.rb) for more details. You can customize this to your particular needs by replacing any of the default components used by `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`.
@@ -55,8 +57,6 @@ If you want to speed up the re-compiling process so you don't wait to run your t
55
57
 
56
58
  [spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy) contains examples of how to set the proc files for this purpose.
57
59
 
58
- If you want to use a testing framework other than RSpec, please submit let us know on the changes you need to do and we'll update the docs.
59
-
60
60
  ![2016-01-27_02-36-43](https://cloud.githubusercontent.com/assets/1118459/12611951/7c56d070-c4a4-11e5-8a80-9615f99960d9.png)
61
61
 
62
62
  ![2016-01-27_03-18-05](https://cloud.githubusercontent.com/assets/1118459/12611975/a8011654-c4a4-11e5-84f9-1baca4835b4b.png)
@@ -5,12 +5,22 @@ If you would like help in migrating between React on Rails versions or help with
5
5
 
6
6
  We specialize in helping companies to quickly and efficiently move from versions before 9 to current. The older versions use the Rails asset pipeline to package client assets. The current and recommended way is to use Webpack 4 for asset preparation. You may also need help migrating from the `rails/webpacker`'s Webpack configuration to a better setup ready for Server Side Rendering.
7
7
 
8
+ ## Upgrading rails/webpacker from v3 to v4
9
+ ### Custom Webpack build file
10
+ The default value for `extract_css` is **false** in `config/webpack.yml`. Custom webpack builds should set this value to true or else no CSS link tags are generated. You have a custom webpack build if you are not using [rails/webpacker](https://github.com/rails/webpacker to setup your Webpack configuration.
11
+
12
+ ```yml
13
+ default: &default
14
+ # other stuff
15
+ extract_css: true
16
+ # by default, extract and emit a css file. The default is false
17
+ ```
18
+
8
19
  ## Upgrading to version 11
9
20
  * Remove `server_render_method` from config/initializers/react_on_rails.rb. Alternate server rendering methods are part of React on Rails Pro. If you want to use a custom renderer, contact justin@shakacode.com. We have a custom node rendering solution in production for egghead.io.
10
21
  * Remove your usage of ENV["TRACE_REACT_ON_RAILS"] usage. You can get all tracing with either specifying **`trace`** at your component or in your config/initializers/react_on_rails.rb file.
11
22
  * ReactOnRails::Utils.server_bundle_file_name and ReactOnRails::Utils.bundle_file_name were removed. React on Rails Pro contains upgrades to enable component and other types caching with React on Rails.
12
23
 
13
-
14
24
  ## Upgrading to version 10
15
25
 
16
26
  Pretty simple:
@@ -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.
@@ -21,7 +21,7 @@ Different markup is generated on the client than on the server. Why does this ha
21
21
 
22
22
  ### The solution
23
23
 
24
- To prevent this, you have to wait until the code chunk is fetched before doing the initial render on the client side. To accomplish this, react on rails allows you to register a renderer. This works just like registering a generator function, except that the function you pass takes three arguments: `renderer(props, railsContext, domNodeId)`, and is responsible for calling `ReactDOM.render` to render the component to the DOM. React on rails will automatically detect when a generator function takes three arguments, and will not call `ReactDOM.render`, instead allowing you to control the initial render yourself.
24
+ To prevent this, you have to wait until the code chunk is fetched before doing the initial render on the client side. To accomplish this, react on rails allows you to register a renderer. This works just like registering a generator function, except that the function you pass takes three arguments: `renderer(props, railsContext, domNodeId)`, and is responsible for calling `ReactDOM.render` or `ReactDOM.hydrate` to render the component to the DOM. React on rails will automatically detect when a generator function takes three arguments, and will not call `ReactDOM.render` or `ReactDOM.hydrate`, instead allowing you to control the initial render yourself. Note, you have to be careful to call `ReactDOM.hydrate` rather than `ReactDOM.render` if you are are server rendering.
25
25
 
26
26
  Here's an example of how you might use this in practice:
27
27
 
@@ -115,7 +115,7 @@ See:
115
115
 
116
116
  - [spec/dummy/client/app/startup/clientRegistration.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/clientRegistration.jsx)
117
117
  - [spec/dummy/client/app/startup/serverRegistration.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/serverRegistration.jsx)
118
- - [spec/dummy/client/app/startup/DeferredRenderAppRenderer.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/DeferredRenderAppRenderer.jsx) <-- Code splitting implemented here
118
+ - [spec/dummy/client/app/startup/DeferredRenderAppClient](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/DeferredRenderAppClient.jsx)<-- Code splitting implemented here
119
119
  - [spec/dummy/client/app/startup/DeferredRenderAppServer.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/DeferredRenderAppServer.jsx)
120
120
  - [spec/dummy/client/app/components/DeferredRender.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/components/DeferredRender.jsx)
121
121
  - [spec/dummy/client/app/components/DeferredRenderAsyncPage.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/components/DeferredRenderAsyncPage.jsx)
@@ -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, Head of E-Commerce
20
+
21
+ [paul@hvmn.com](mailto:paul@hvmn.com), [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/)
@@ -0,0 +1,13 @@
1
+ # ResortPass Testimonial, by Leora Juster, December 10, 2018
2
+
3
+ Many can write code that "works." Even fewer can write sophisticated code that both works and reflects a deep understanding of the technologies and paradigms involved. Only a select few can do the aforementioned while assisting in managing the expectations and time constraints of less technically informed members of software product teams to make the best design decisions possible. Justin and his team were instrumental in assisting us in setting design foundations and standards for our transition to a react on rails application. Just three months of work with the team at Shaka code and we have a main page of our application server-side rendering at exponentially improved speeds. The code and CSS files are well-organized and contain repeatable patterns easy to understand, allowing my team to build on what has already been accomplished. I learned a great deal from my interactions with Justin and his team, as they are just as great teachers as they are developers, and feel like I get to continually learn from them as I build on top of their code. Their different support and pro plan options make it easy to build a continuous professional relationship despite fluctuations in my team's funding, and their team is always extremely personable, punctual, and professional.
4
+
5
+ Leora Juster, Full-Stack Lead Software Developer
6
+
7
+ [LinkedIn](https://www.linkedin.com/in/leora-juster-38933050)
8
+
9
+ ![image](https://user-images.githubusercontent.com/1118459/50050877-30399b00-00ab-11e9-9e52-2977de45ccae.png)
10
+
11
+ [ResortPass](https://resortpass.com/)
12
+
13
+ [![2018-12-15_20-48-35](https://user-images.githubusercontent.com/1118459/50050866-03858380-00ab-11e9-8588-461112f8045b.png)](https://resortpass.com/)
@@ -0,0 +1,28 @@
1
+ # Testimonials
2
+ # [HVMN Testimonial, Written by Paul Benigeri, October 12, 2018](./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
+ Full writeup [here](./hvmn.md).
7
+
8
+ ---
9
+
10
+ # [Leora from ResortPass](./resortpass.md), December 10, 2018
11
+
12
+ Justin and his team were instrumental in assisting us in setting design foundations and standards for our transition to a react on rails application. Just three months of work with the team at Shaka code and we have a main page of our application server-side rendering at exponentially improved speeds.
13
+
14
+ Full writeup [here](./testimonials/resortpass.md).
15
+
16
+ ---
17
+
18
+ From Joel Hooks, Co-Founder, Chief Nerd at [egghead.io](https://egghead.io/), January 30, 2017:
19
+
20
+ ![2017-01-30_11-33-59](https://cloud.githubusercontent.com/assets/1118459/22443635/b3549fb4-e6e3-11e6-8ea2-6f589dc93ed3.png)
21
+
22
+ ---
23
+
24
+ From Kyle Maune of Cooper Aerial, May 4, 2018
25
+
26
+ ![image](https://user-images.githubusercontent.com/1118459/40891236-9b0b406e-671d-11e8-80ee-c026dbd1d5a2.png)
27
+
28
+ For more testimonials, see [Live Projects](PROJECTS.md) and [Kudos](KUDOS.md).
@@ -1,6 +1,6 @@
1
1
  # React on Rails Basic Tutorial
2
2
 
3
- This tutorial guides you through setting up a new or existing Rails app with **React on Rails**, demonstrating Rails + React + Redux + Server Rendering. It is updated to 11.1.4.
3
+ This tutorial guides you through setting up a new or existing Rails app with **React on Rails**, demonstrating Rails + React + Redux + Server Rendering. It is updated to 11.2.1.
4
4
 
5
5
  After finishing this tutorial you will get an application that can do the following (live on Heroku):
6
6
 
@@ -47,19 +47,20 @@ 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
56
57
  bundle exec rails webpacker:install:react
57
58
  ```
58
59
 
59
- Add the **React On Rails** gem to your Gemfile:
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.2.1' # 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.
@@ -83,15 +84,40 @@ rails generate react_on_rails:install
83
84
  bundle && yarn
84
85
  ```
85
86
 
86
- and then run server with
87
+ Then run server with static client side files:
87
88
 
88
89
  ```
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
+ To run with the webpack-dev-server:
94
+ ```
95
+ foreman start -f Procfile.dev-server
96
+ ```
97
+
98
+ Visit [http://localhost:3000/hello_world](http://localhost:3000/hello_world) and see your **React On Rails** app running!
93
99
  Note, foreman defaults to PORT 5000 unless you set the value of PORT in your environment or in the Procfile.
94
100
 
101
+ ## Using a pre-release of rails/webpacker
102
+ Until `rails/webpacker` v4 ships, or if you ever want to try out the master branch, you can modify the React on Rails tutorial instructions slightly. You can see the sequence of commits here. To summarize:
103
+
104
+ **Don't run `rails new` with the `--webpack=react` option**. Instead, add the webpacker gem to the Gemfile such that it points to master, like this if `11.2.1` is the version you want.
105
+
106
+ ```ruby
107
+ gem 'webpacker', github: "rails/webpacker"
108
+ gem 'react_on_rails', '11.2.1' # always use exact version
109
+ ```
110
+
111
+ Then run these commands:
112
+
113
+ ```sh
114
+ bundle exec rails webpacker:install
115
+ yarn add "rails/webpacker" # because the installer has a bug that puts in an invalid version in your package.json.
116
+ bundle exec rails webpacker:install:react
117
+ yarn add --dev webpack-dev-server
118
+ run rails generate react_on_rails:install && bundle && yarn
119
+ ```
120
+
95
121
  ### Custom IP & PORT setup (Cloud9 example)
96
122
 
97
123
  In case you are running some custom setup with different IP or PORT you should also edit Procfile.dev. For example to be able to run on free Cloud9 IDE we are putting IP 0.0.0.0 and PORT 8080. The default generated file `Procfile.dev` uses `-p 3000`.
@@ -115,7 +141,7 @@ It's super important to exclude certain directories from RubyMine or else it wil
115
141
  ### Create Your Heroku App
116
142
  *Assuming you can login to heroku.com and have logged into to your shell for heroku.*
117
143
 
118
- 1. Visit https://dashboard.heroku.com/new and create an app, say named `my-name-react-on-rails`:
144
+ 1. Visit [https://dashboard.heroku.com/new](https://dashboard.heroku.com/new) and create an app, say named `my-name-react-on-rails`:
119
145
 
120
146
  ![06](https://cloud.githubusercontent.com/assets/20628911/17465014/1f29bf3c-5cf4-11e6-869f-4215987ae854.png)
121
147
 
@@ -137,10 +163,11 @@ Set heroku to use multiple buildpacks:
137
163
  gem 'pg'
138
164
  ```
139
165
 
140
- ![07](https://cloud.githubusercontent.com/assets/20628911/17465015/1f2f4042-5cf4-11e6-8287-2fb077550809.png)
166
+ 2. Run `bundle`
141
167
 
168
+ ![07](https://cloud.githubusercontent.com/assets/20628911/17465015/1f2f4042-5cf4-11e6-8287-2fb077550809.png)
142
169
 
143
- 2. Replace your `database.yml` file with this (assuming your app name is "ror").
170
+ 3. Replace your `database.yml` file with this (assuming your app name is "ror").
144
171
 
145
172
  ```yml
146
173
  default: &default
@@ -185,11 +212,15 @@ root "hello_world#index"
185
212
 
186
213
  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
214
 
215
+ Create `/Procfile`. This is what Heroku uses to start your app.
216
+
188
217
  `Procfile`
189
218
  ```
190
219
  web: bundle exec puma -C config/puma.rb
191
220
  ```
192
221
 
222
+ 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:
223
+
193
224
  `config/puma.rb`
194
225
  ```rb
195
226
  workers Integer(ENV['WEB_CONCURRENCY'] || 2)
@@ -213,8 +244,89 @@ Then after all changes are done don't forget to commit them with git and finally
213
244
 
214
245
  ```
215
246
  git add -A
216
- git commit -m "Latest changes"
247
+ git commit -m "Changes for Heroku"
248
+ git push heroku master
249
+ ```
250
+
251
+ Then run:
252
+
253
+ ```
254
+ heroku open
255
+ ```
256
+
257
+ and you will see your live app and you can share this URL with your friends. Congrats!
258
+
259
+
260
+ ## Turning on Server Rendering
261
+
262
+ You can turn on server rendering by simply changing the `prerender` option to `true`:
263
+
264
+ ```erb
265
+ <%= react_component("HelloWorld", props: @hello_world_props, prerender: true) %>
266
+ ```
267
+
268
+ Then push to Heroku:
269
+
270
+ ```
271
+ git add -A
272
+ git commit -m "Enable server rendering"
217
273
  git push heroku master
218
274
  ```
219
275
 
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).
276
+ 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:
277
+
278
+ ```html
279
+ <div id="HelloWorld-react-component-b7ae1dc6-396c-411d-886a-269633b3f604"></div>
280
+ ```
281
+
282
+ versus with server rendering:
283
+
284
+ ```html
285
+ <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>
286
+ ```
287
+
288
+ For more details on server rendering, see:
289
+
290
+ + [Client vs. Server Rendering](./basics/client-vs-server-rendering.md)
291
+ + [React Server Rendering](./basics/react-server-rendering.md)
292
+
293
+ ## Moving from the Rails default `/app/javascript` to the recommended `/client` structure
294
+
295
+ 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.
296
+
297
+
298
+ 1. Move the directory:
299
+
300
+ ```
301
+ mv app/javascript client
302
+ ```
303
+
304
+ 2. Edit your `/config/webpacker.yml` file. Change the `default/source_path`:
305
+
306
+ ```yml
307
+ source_path: client
308
+ ```
309
+
310
+ ## Using HMR with the rails/webpacker setup
311
+
312
+ Start the app using `foreman start -f Procfile.dev-server`.
313
+
314
+ When you change a JSX file and save, the browser will automatically refresh!
315
+
316
+ So you get some basics from HMR with no code changes. If you want to go further, take a look at these links:
317
+
318
+ * https://github.com/rails/webpacker/blob/master/docs/webpack-dev-server.md
319
+ * https://webpack.js.org/configuration/dev-server/
320
+ * https://webpack.js.org/concepts/hot-module-replacement/
321
+ * https://gaearon.github.io/react-hot-loader/getstarted/
322
+ * https://github.com/gaearon/react-hot-loader
323
+
324
+ 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.
325
+
326
+ ## Conclusion
327
+
328
+ * 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)
329
+
330
+ Feedback is greatly appreciated! As are stars on github!
331
+
332
+ 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.