react_on_rails 12.0.1 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +27 -13
  3. data/.eslintrc +2 -1
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +23 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.github/workflows/lint-js-and-ruby.yml +53 -0
  7. data/.github/workflows/main.yml +178 -0
  8. data/.github/workflows/package-js-tests.yml +35 -0
  9. data/.github/workflows/rspec-package-specs.yml +45 -0
  10. data/.gitignore +0 -3
  11. data/.prettierignore +2 -0
  12. data/.prettierrc +0 -3
  13. data/.rubocop.yml +48 -39
  14. data/.travis.yml +3 -1
  15. data/CHANGELOG.md +112 -25
  16. data/CONTRIBUTING.md +4 -3
  17. data/Gemfile +1 -33
  18. data/Gemfile.development_dependencies +52 -0
  19. data/NEWS.md +14 -4
  20. data/REACT-ON-RAILS-PRO-LICENSE +1 -1
  21. data/README.md +42 -324
  22. data/Rakefile +1 -1
  23. data/SUMMARY.md +22 -13
  24. data/docs/{basics → additional-details}/generator-details.md +1 -6
  25. data/docs/{outdated → additional-details}/manual-installation-overview.md +6 -6
  26. data/docs/additional-details/recommended-project-structure.md +69 -0
  27. data/docs/additional-details/upgrade-webpacker-v3-to-v4.md +10 -0
  28. data/docs/api/javascript-api.md +2 -2
  29. data/docs/api/redux-store-api.md +3 -3
  30. data/docs/api/view-helpers-api.md +7 -8
  31. data/docs/contributor-info/linters.md +5 -6
  32. data/docs/contributor-info/pull-requests.md +2 -4
  33. data/docs/contributor-info/releasing.md +1 -1
  34. data/docs/{basics → deployment}/heroku-deployment.md +16 -5
  35. data/docs/{basics → guides}/client-vs-server-rendering.md +4 -2
  36. data/docs/{basics → guides}/configuration.md +65 -31
  37. data/docs/guides/deployment.md +4 -0
  38. data/docs/guides/getting-started.md +183 -0
  39. data/docs/guides/hmr-and-hot-reloading-with-the-webpack-dev-server.md +104 -0
  40. data/docs/{outdated → guides}/how-react-on-rails-works.md +10 -10
  41. data/docs/guides/how-to-conditionally-server-render-based-on-device-type.md +39 -0
  42. data/docs/guides/how-to-use-different-files-for-client-and-server-rendering.md +98 -0
  43. data/docs/{basics → guides}/installation-into-an-existing-rails-app.md +14 -7
  44. data/docs/guides/rails-webpacker-react-integration-options.md +182 -0
  45. data/docs/guides/react-on-rails-overview.md +30 -0
  46. data/docs/{basics → guides}/react-server-rendering.md +8 -5
  47. data/docs/{basics → guides}/rspec-configuration.md +11 -11
  48. data/docs/{tutorial.md → guides/tutorial.md} +46 -50
  49. data/docs/{basics → guides}/upgrading-react-on-rails.md +56 -18
  50. data/docs/guides/webpack-configuration.md +42 -0
  51. data/docs/home.md +23 -0
  52. data/docs/{outdated → javascript}/code-splitting.md +5 -5
  53. data/docs/{additional-reading → javascript}/converting-from-custom-webpack-config-to-rails-webpacker-config.md +4 -4
  54. data/docs/{additional-reading → javascript}/images.md +5 -6
  55. data/docs/{articles.md → misc/articles.md} +1 -1
  56. data/docs/misc/doctrine.md +5 -6
  57. data/docs/outdated/deferred-rendering.md +39 -0
  58. data/docs/outdated/rails-assets-relative-paths.md +3 -3
  59. data/docs/outdated/rails-assets.md +8 -8
  60. data/docs/outdated/rails3.md +2 -2
  61. data/docs/{additional-reading → rails}/convert-rails-5-api-only-app.md +1 -1
  62. data/docs/{additional-reading → rails}/rails-engine-integration.md +3 -12
  63. data/docs/{additional-reading → rails}/turbolinks.md +13 -1
  64. data/docs/react-on-rails-pro/react-on-rails-pro.md +43 -0
  65. data/docs/testimonials/testimonials.md +6 -6
  66. data/lib/generators/react_on_rails/base_generator.rb +64 -12
  67. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
  68. data/lib/generators/react_on_rails/generator_helper.rb +4 -0
  69. data/lib/generators/react_on_rails/templates/.eslintrc +3 -1
  70. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +4 -8
  71. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static +9 -0
  72. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +2 -1
  73. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +4 -0
  74. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorldServer.js +5 -0
  75. data/lib/generators/react_on_rails/templates/base/base/app/javascript/packs/server-bundle.js +8 -0
  76. data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb +1 -0
  77. data/lib/generators/react_on_rails/templates/base/base/babel.config.js.tt +32 -0
  78. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +3 -3
  79. data/lib/generators/react_on_rails/templates/base/base/config/webpack/clientWebpackConfig.js.tt +17 -0
  80. data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +15 -0
  81. data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +25 -0
  82. data/lib/generators/react_on_rails/templates/base/base/config/webpack/production.js.tt +9 -0
  83. data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt +117 -0
  84. data/lib/generators/react_on_rails/templates/base/base/config/webpack/test.js.tt +6 -0
  85. data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpack.config.js.tt +15 -0
  86. data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpackConfig.js.tt +36 -0
  87. data/lib/generators/react_on_rails/templates/base/base/config/webpacker.yml +62 -0
  88. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +8 -2
  89. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +1 -1
  90. data/lib/generators/react_on_rails/templates/dev_tests/spec/{features → system}/hello_world_spec.rb +2 -2
  91. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +2 -1
  92. data/lib/react_on_rails/configuration.rb +42 -41
  93. data/lib/react_on_rails/git_utils.rb +3 -3
  94. data/lib/react_on_rails/helper.rb +54 -28
  95. data/lib/react_on_rails/json_parse_error.rb +1 -1
  96. data/lib/react_on_rails/locales/base.rb +11 -15
  97. data/lib/react_on_rails/locales/to_js.rb +0 -4
  98. data/lib/react_on_rails/locales/to_json.rb +0 -4
  99. data/lib/react_on_rails/prerender_error.rb +6 -3
  100. data/lib/react_on_rails/react_component/render_options.rb +30 -7
  101. data/lib/react_on_rails/server_rendering_js_code.rb +13 -0
  102. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +41 -13
  103. data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +1 -1
  104. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +3 -3
  105. data/lib/react_on_rails/test_helper.rb +4 -2
  106. data/lib/react_on_rails/utils.rb +24 -4
  107. data/lib/react_on_rails/version.rb +1 -1
  108. data/lib/react_on_rails/webpacker_utils.rb +9 -10
  109. data/lib/tasks/assets.rake +19 -50
  110. data/lib/tasks/locale.rake +1 -2
  111. data/package.json +24 -29
  112. data/rakelib/docker.rake +0 -5
  113. data/rakelib/example_type.rb +10 -3
  114. data/rakelib/examples.rake +3 -5
  115. data/rakelib/lint.rake +3 -9
  116. data/rakelib/release.rake +35 -15
  117. data/rakelib/run_rspec.rake +10 -11
  118. data/rakelib/task_helpers.rb +16 -4
  119. data/react_on_rails.gemspec +5 -20
  120. data/yarn.lock +2616 -5190
  121. metadata +86 -256
  122. data/.release-it.json +0 -3
  123. data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +0 -10
  124. data/docs/additional-reading/webpack-dev-server.md +0 -15
  125. data/docs/basics/deployment.md +0 -4
  126. data/docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md +0 -49
  127. data/docs/basics/recommended-project-structure.md +0 -77
  128. data/docs/basics/webpack-configuration.md +0 -50
  129. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr +0 -26
  130. data/ruby-lint.yml +0 -25
  131. /data/docs/{basics → additional-details}/migrating-from-react-rails.md +0 -0
  132. /data/docs/{additional-reading → additional-details}/updating-dependencies.md +0 -0
  133. /data/docs/{additional-reading → deployment}/elastic-beanstalk.md +0 -0
  134. /data/docs/{basics → guides}/i18n.md +0 -0
  135. /data/docs/{basics → guides}/minitest-configuration.md +0 -0
  136. /data/docs/{basics → guides}/render-functions-and-railscontext.md +0 -0
  137. /data/docs/{additional-reading → javascript}/angular-js-integration-migration.md +0 -0
  138. /data/docs/{additional-reading → javascript}/asset-pipeline.md +0 -0
  139. /data/docs/{additional-reading → javascript}/capistrano-deployment.md +0 -0
  140. /data/docs/{additional-reading → javascript}/credits.md +0 -0
  141. /data/docs/{additional-reading → javascript}/foreman-issues.md +0 -0
  142. /data/docs/{additional-reading → javascript}/node-dependencies-and-npm.md +0 -0
  143. /data/docs/{additional-reading → javascript}/react-and-redux.md +0 -0
  144. /data/docs/{additional-reading → javascript}/react-helmet.md +0 -0
  145. /data/docs/{additional-reading → javascript}/react-router.md +0 -0
  146. /data/docs/{additional-reading → javascript}/server-rendering-tips.md +0 -0
  147. /data/docs/{additional-reading → javascript}/troubleshooting-when-using-webpacker.md +0 -0
  148. /data/docs/{additional-reading → javascript}/webpack-v1-notes.md +0 -0
  149. /data/docs/{additional-reading → javascript}/webpack.md +0 -0
  150. /data/docs/{coding-style → misc}/style.md +0 -0
  151. /data/docs/{additional-reading → misc}/tips.md +0 -0
  152. /data/docs/{additional-reading → rails}/rails_view_rendering_from_inline_javascript.md +0 -0
@@ -0,0 +1,69 @@
1
+ # Recommended Project structure
2
+
3
+ The React on Rails generator uses the standard `rails/webpacker` convention of this structure:
4
+
5
+ ```yml
6
+ app/javascript:
7
+ ├── bundles:
8
+ │ # Logical groups of files that can be used for code splitting
9
+ │ └── hello-world-bundle.js
10
+ ├── packs:
11
+ │ # only webpack entry files here
12
+ │ └── hello-world-bundle.js
13
+ ```
14
+
15
+ Per the example repo [shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh),
16
+ you should consider keeping your codebase mostly consistent with the defaults for [rails/webpacker](https://github.com/rails/webpacker).
17
+
18
+ ## Steps to convert from the generator defaults to use a `/client` directory for source code
19
+
20
+ 1. Move the directory:
21
+
22
+ ```
23
+ mv app/javascript client
24
+ ```
25
+
26
+ 2. Edit your `/config/webpacker.yml` file. Change the `default/source_path`:
27
+
28
+ ```yml
29
+ source_path: client
30
+ ```
31
+
32
+ ## Moving node_modules from `/` to `/client` with a custom webpack setup.
33
+
34
+ `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.
35
+
36
+ 1. Move the `/package.json` to `/client/package.json`
37
+ 2. Create a `/package.json` that delegates to `/client/package.json`.
38
+ ```
39
+ "scripts": {
40
+ "heroku-postbuild": "cd ./client && yarn"
41
+ },
42
+ ```
43
+ 3. If your node_modules directory is not at the top level of the Rails project, then you will need to set the
44
+ ENV value of WEBPACKER_CONFIG to the location of the `config/webpacker.yml` file per [rails/webpacker PR 2561](https://github.com/rails/webpacker/pull/2561).
45
+
46
+ ## CSS, Sass, Fonts, and Images
47
+ Should you move your styling assets to Webpack? Or stick with the plain Rails asset pipeline. It depends!
48
+
49
+ Here's a good discussion of this option: [Why does Rails 6 include both Webpacker and Sprockets?](https://rossta.net/blog/why-does-rails-install-both-webpacker-and-sprockets.html).
50
+
51
+ You have 2 basic choices:
52
+
53
+ ### Simple Rails Way
54
+ This isn't really any technique, as you keep handling all your styling assets using Rails standard tools, such as using the [sass-rails gem](https://rubygems.org/gems/sass-rails/versions/5.0.4). Basically, Webpack doesn't get involved with styling. Your Rails layouts just doing the styling the standard Rails way.
55
+
56
+ #### Advantages to the Simple Rails Way
57
+ 1. Much simpler! There's no changes really from your current processes.
58
+
59
+ ### Using Webpack to Manage Styling Assets
60
+ This technique involves customization of the webpack config files to generate CSS, image, and font assets.
61
+
62
+ #### Directory structure
63
+ 1. `/client/app/assets`: Assets for CSS for client app.
64
+ 1. `/client/app/assets/fonts` and `/client/app/assets/styles`: Globally shared assets for styling. Note, most Sass and image assets will be stored next to the JavaScript files.
65
+
66
+ #### Advantages to having Webpack Manage Styles
67
+ 1. You can use [CSS modules](https://github.com/css-modules/css-modules), which is super compelling once you seen the benefits.
68
+ 1. You can use CSS in JS.
69
+ 1. You can do hot reloading of your assets. Thus, you do not have to refresh your web page to see asset change, including changing styles.
@@ -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](https://github.com/shakacode/react_on_rails/tree/master/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](https://github.com/shakacode/react_on_rails/tree/master/lib/install/config/.browserslistrc) to `/`.
8
+ 1. Merge any differences between [config/webpacker.yml](https://github.com/shakacode/react_on_rails/tree/master/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).
@@ -34,7 +34,7 @@ The best source of docs is the main [ReactOnRails.js](https://github.com/shakaco
34
34
  * Your Ruby code with get this Object as a Hash containing keys componentHtml and any other
35
35
  * custom keys that you added:
36
36
  * { renderedHtml: { componentHtml, customKey1, customKey2 } }
37
- * See the example in /docs/additional-reading/react-helmet.md
37
+ * See the example in https://www.shakacode.com/react-on-rails/docs/javascript/react-helmet
38
38
  * @param components (key is component name, value is component)
39
39
  */
40
40
  register(components)
@@ -69,7 +69,7 @@ The best source of docs is the main [ReactOnRails.js](https://github.com/shakaco
69
69
  * Allow directly calling the page loaded script in case the default events that trigger react
70
70
  * rendering are not sufficient, such as when loading JavaScript asynchronously with TurboLinks:
71
71
  * More details can be found here:
72
- * https://github.com/shakacode/react_on_rails/blob/master/docs/additional-reading/turbolinks.md
72
+ * https://www.shakacode.com/react-on-rails/docs/rails/turbolinks
73
73
  */
74
74
  reactOnRailsPageLoaded()
75
75
 
@@ -13,7 +13,7 @@ Consider using the `redux_store` helper for the two following use cases:
13
13
 
14
14
  ## Multiple React Components on a Page with One Store
15
15
 
16
- You may wish to have 2 React components share the same the Redux store. For example, if your navbar is a React component, you may want it to use the same store as your component in the main area of the page. You may even want multiple React components in the main area, which allows for greater modularity. Also, you may want this to work with Turbolinks to minimize reloading the JavaScript.
16
+ You may wish to have 2 React components share the same the Redux store. For example, if your navbar is a React component, you may want it to use the same store as your component in the main area of the page. You may even want multiple React components in the main area, which allows for greater modularity. Also, you may want this to work with Turbolinks to minimize reloading the JavaScript.
17
17
 
18
18
  A good example of this would be something like a notifications counter in a header. As each notification is read in the body of the page, you would like to update the header. If both the header and body share the same Redux store, then this is trivial. Otherwise, we have to rely on other solutions, such as the header polling the server to see how many unread notifications exist.
19
19
 
@@ -98,5 +98,5 @@ Place this view helper (no parameters) at the end of your shared layout so React
98
98
 
99
99
  # More Details
100
100
 
101
- * [lib/react_on_rails/controller.rb](../../lib/react_on_rails/controller.rb) source
102
- * [lib/react_on_rails/helper.rb](../../lib/react_on_rails/helper.rb) source
101
+ * [lib/react_on_rails/controller.rb](https://github.com/shakacode/react_on_rails/tree/master/lib/react_on_rails/controller.rb) source
102
+ * [lib/react_on_rails/helper.rb](https://github.com/shakacode/react_on_rails/tree/master/lib/react_on_rails/helper.rb) source
@@ -23,7 +23,7 @@ Uncommonly used options:
23
23
  ```
24
24
 
25
25
  - **component_name:** Can be a React component, created using a React Function Component, an ES6 class or a Render-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). Note, a "renderer function" is a special type of "Render-Function." A "renderer function" takes a 3rd param of a DOM ID.
26
- All options except `props, id, html_options` will inherit from your `react_on_rails.rb` initializer, as described [here](../basics/configuration.md).
26
+ All options except `props, id, html_options` will inherit from your `react_on_rails.rb` initializer, as described [here](https://www.shakacode.com/react-on-rails/docs/guides/configuration/).
27
27
  - **general options:**
28
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.
29
29
  - **prerender:** enable server-side rendering of a component. Set to false when debugging!
@@ -43,7 +43,7 @@ Uncommonly used options:
43
43
  `react_component_hash` is used to return multiple HTML strings for server rendering, such as for
44
44
  adding meta-tags to a page. It is exactly like react_component except for the following:
45
45
 
46
- 1. `prerender: true` is automatically added to options, as this method doesn't make sense for
46
+ 1. `prerender: true` is automatically added to options, as this method doesn't make sense for
47
47
  client only rendering.
48
48
  2. Your JavaScript Render-Function for server rendering must return an Object rather than a React Component.
49
49
  3. Your view code must expect an object and not a string.
@@ -100,7 +100,7 @@ You can call `rails_context` or `rails_context(server_side: true|false)` from yo
100
100
 
101
101
  A "renderer function" is a Render-Function that accepts three arguments (rather than 2): `(props, railsContext, domNodeId) => { ... }`. Instead of returning a React component, a renderer is responsible for installing a callback that will call `ReactDOM.render` (in React 16+, `ReactDOM.hydrate`) to render a React component into the DOM. The "renderer function" is called at the same time the document ready event would instantate the React components into the DOM.
102
102
 
103
- Why would you want to call `ReactDOM.hydrate` yourself? One possible use case is [code splitting](docs/outdated/code-splitting.md). In a nutshell, you don't want to load the React component on the DOM node yet. So you want to install some handler that will call `ReactDOM.hydrate` at a later time. In the case of code splitting with server rendering, the server rendered code has any async code loaded and used to server render. Thus, the client code must also fully load any asynch code before server rendering. Otherwise, the client code would first render partially, not matching the server rendering, and then a second later, the full code would render, resulting in an unpleasant flashing on the screen.
103
+ Why would you want to call `ReactDOM.hydrate` yourself? One possible use case is [code splitting](https://www.shakacode.com/react-on-rails/docs/javascript/code-splitting/). In a nutshell, you don't want to load the React component on the DOM node yet. So you want to install some handler that will call `ReactDOM.hydrate` at a later time. In the case of code splitting with server rendering, the server rendered code has any async code loaded and used to server render. Thus, the client code must also fully load any asynch code before server rendering. Otherwise, the client code would first render partially, not matching the server rendering, and then a second later, the full code would render, resulting in an unpleasant flashing on the screen.
104
104
 
105
105
  Renderer functions are not meant to be used on the server since there's no DOM on the server. Instead, use a Render-Function. Attempting to server render with a renderer function will throw an error.
106
106
 
@@ -110,9 +110,9 @@ Renderer functions are not meant to be used on the server since there's no DOM o
110
110
 
111
111
  [React Router](https://github.com/reactjs/react-router) is supported, including server-side rendering! See:
112
112
 
113
- 1. [React on Rails docs for react-router](../additional-reading/react-router.md)
114
- 2. Examples in [spec/dummy/app/views/react_router](../../spec/dummy/app/views/react_router) and follow to the JavaScript code in the [spec/dummy/client/app/startup/ServerRouterApp.jsx](../../spec/dummy/client/app/startup/ServerRouterApp.jsx).
115
- 3. [Code Splitting docs](docs/outdated/code-splitting.md) for information about how to set up code splitting for server rendered routes.
113
+ 1. [React on Rails docs for react-router](https://www.shakacode.com/react-on-rails/docs/javascript/react-router/)
114
+ 2. Examples in [spec/dummy/app/views/react_router](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/app/views/react_router) and follow to the JavaScript code in the [spec/dummy/client/app/startup/ServerRouterApp.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/ServerRouterApp.jsx).
115
+ 3. [Code Splitting docs](https://www.shakacode.com/react-on-rails/docs/javascript/code-splitting/) for information about how to set up code splitting for server rendered routes.
116
116
 
117
117
  ------------
118
118
 
@@ -129,5 +129,4 @@ This is a helper method that takes any JavaScript expression and returns the out
129
129
 
130
130
  # More details
131
131
 
132
- See the [lib/react_on_rails/helper.rb](../../lib/react_on_rails/helper.rb) source.
133
-
132
+ See the [lib/react_on_rails/helper.rb](https://github.com/shakacode/react_on_rails/tree/master/lib/react_on_rails/helper.rb) source.
@@ -1,5 +1,5 @@
1
1
  # Linters
2
- These linters support the [ShakaCode Style Guidelines](./style.md)
2
+ These linters support the [ShakaCode Style Guidelines](https://www.shakacode.com/react-on-rails/docs/misc/style/)
3
3
 
4
4
  ## Autofix!
5
5
 
@@ -15,9 +15,9 @@ If you haven't tried the autofix options for `eslint` and `rubocop`, you're seri
15
15
  ```
16
16
  eslint --fix .
17
17
  ```
18
-
19
- or
20
-
18
+
19
+ or
20
+
21
21
  ```
22
22
  npm run lint -- --fix
23
23
  ```
@@ -32,7 +32,7 @@ Rules are configured with a 0, 1 or 2. Setting a rule to 0 is turning it off, se
32
32
 
33
33
  Rules can also take a few additional options. In this case, the rule can be set to an array, the first item of which is the 0/1/2 flag and the rest are options.
34
34
 
35
- See file [.eslintrc](../../client/.eslintrc) for examples of configuration
35
+ See file [.eslintrc](https://github.com/shakacode/react_on_rails/tree/master/.eslintrc) for examples of configuration
36
36
 
37
37
  ### Specify/Override rules in code
38
38
 
@@ -66,4 +66,3 @@ You can disable all rules for a line or block, or only specific rules, as shown
66
66
  * [ESLint quick start](http://untilfalse.com/eslint-quick-start/)
67
67
  * [RuboCop](https://github.com/bbatsov/rubocop)
68
68
  * [ESLint](http://eslint.org/)
69
-
@@ -1,4 +1,4 @@
1
- # Pull Requests
1
+ # Pull Requests
2
2
 
3
3
  ## Checklist before Committing
4
4
  1. `rake`: runs all linters and specs (you need Docker setup, see below)
@@ -36,9 +36,7 @@ When making doc changes, we want the change to work on both the gitbook and the
36
36
 
37
37
  ### Links to other docs:
38
38
  * When making references to doc files, use a relative URL path like:
39
- `[Installation Overview](docs/basics/installation-overview.md)`
39
+ `[Installation Overview](https://www.shakacode.com/react-on-rails/docs/additional-details/manual-installation-overview/)`
40
40
 
41
41
  * When making references to source code files, use a full url path like:
42
42
  `[spec/dummy/config/initializers/react_on_rails.rb](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/initializers/react_on_rails.rb)`
43
-
44
-
@@ -3,7 +3,7 @@
3
3
  We're now releasing this as a combined ruby gem plus npm package. We will keep the version numbers in sync.
4
4
 
5
5
  ## Testing the Gem before Release from a Rails App
6
- See [Contributing](../../CONTRIBUTING.md)
6
+ See [Contributing](https://github.com/shakacode/react_on_rails/tree/master/CONTRIBUTING.md)
7
7
 
8
8
  ## Releasing a new gem version
9
9
  Run `rake -D release` to see instructions on how to release via the rake task.
@@ -16,9 +16,20 @@ For more information, see [Using Multiple Buildpacks for an App](https://devcent
16
16
 
17
17
  ### rails/webpacker webpack configuration
18
18
  If you're using the standard rails/webpacker configuration of webpack, then rails/webpacker
19
- will automatically modify or create an assets:precompile task to build your assets.
19
+ will automatically modify or create an assets:precompile task to build your assets.
20
20
 
21
- ### custom webpack configuration
22
- If you're a custom webpack configuration, and you **do not have the default
23
- `config/webpack/production.js`** file, then the `config/initializers/react_on_rails.rb`
24
- configuration `config.build_production_command` will be used.
21
+ Alternatively, you can specify `config.build_production_command` to have
22
+ react_on_rails invoke a command for you during assets:precompile.
23
+
24
+ ```
25
+ config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/webpacker"
26
+ ```
27
+
28
+ ### Consider Removing Webpacker's clean task
29
+
30
+ If you are deploying on Heroku, then you don't need Webpacker's clean task which
31
+ might delete files that you need.
32
+
33
+ ```
34
+ Rake::Task['webpacker:clean'].clear
35
+ ```
@@ -1,9 +1,11 @@
1
1
  # Client-Side Rendering vs. Server-Side Rendering
2
2
 
3
+ *Also, see [our react server-rendering documentation](https://www.shakacode.com/react-on-rails/docs/guides/react-server-rendering/).*
4
+
3
5
  In most cases, you should use the `prerender: false` (default behavior) with the provided helper method to render the React component from your Rails views. In some cases, such as when SEO is vital, or many users will not have JavaScript enabled, you can enable server-rendering by passing `prerender: true` to your helper, or you can simply change the default in `config/initializers/react_on_rails`.
4
6
 
5
7
  Now the server will interpret your JavaScript. The default is to use [ExecJS](https://github.com/rails/execjs) and pass the resulting HTML to the client. We recommend using [mini_racer](https://github.com/discourse/mini_racer) as ExecJS's runtime.
6
-
8
+
7
9
  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).
8
10
 
9
11
  If you open the HTML source of any web page using React on Rails, you'll see the 3 parts of React on Rails rendering:
@@ -16,7 +18,7 @@ If you open the HTML source of any web page using React on Rails, you'll see the
16
18
 
17
19
  # Different Server-Side Rendering Code (and a Server-Specific Bundle)
18
20
 
19
- You may want different code for your server-rendered components running server side versus client side. For example, if you have an animation that runs when a component is displayed, you might need to turn that off when server rendering. One way to handle this is conditional code like `if (window) { doClientOnlyCode() }`.
21
+ You may want different code for your server-rendered components running server side versus client side. For example, if you have an animation that runs when a component is displayed, you might need to turn that off when server rendering. One way to handle this is conditional code like `if (window) { doClientOnlyCode() }`.
20
22
 
21
23
  Another way is to use a separate webpack configuration file that can use a different server side entry file, like 'serverRegistration.js' as opposed to 'clientRegistration.js.' That would set up different code for server rendering.
22
24
 
@@ -12,7 +12,7 @@ default: &default
12
12
  # public_output_path folder
13
13
  manifest: manifest.json
14
14
  cache_manifest: false
15
-
15
+
16
16
  # Source path is used to check if webpack compilation needs to be run for `compile: true`
17
17
  source_path: client/app
18
18
 
@@ -24,7 +24,7 @@ development:
24
24
  test:
25
25
  <<: *default
26
26
  # Ensure that webpacker invokes webpack to build files for tests if not using the
27
- # ReactOnRails rspec helper.
27
+ # ReactOnRails rspec helper.
28
28
  compile: true
29
29
 
30
30
  # Generated files for tests, in /public/webpack/test
@@ -49,7 +49,7 @@ for all client files, including your sources and node_modules.
49
49
  ReactOnRails.configure do |config|
50
50
  # `trace`: General debugging flag.
51
51
  # The default is true for development, off otherwise.
52
- # With true, you get detailed logs of rendering and stack traces if you call setTimout,
52
+ # With true, you get detailed logs of rendering and stack traces if you call setTimout,
53
53
  # setInterval, clearTimout when server rendering.
54
54
  config.trace = Rails.env.development? # default
55
55
 
@@ -57,28 +57,35 @@ ReactOnRails.configure do |config|
57
57
  # false ==> Sets the dom id to "#{react_component_name}-react-component"
58
58
  # true ==> Adds "-#{SecureRandom.uuid}" to that ID
59
59
  # If you might use multiple instances of the same React component on a Rails page, then
60
- # it is convenient to set this to true or else you have to either manually set the ids to
60
+ # it is convenient to set this to true or else you have to either manually set the ids to
61
61
  # avoid collisions. Most newer apps will have only one instance of a component on a page,
62
62
  # so this should be false in most cases.
63
63
  # This value can be overridden for a given call to react_component
64
64
  config.random_dom_id = true # default
65
65
 
66
- # defaults to "" (top level)
67
- config.node_modules_location = "client" # If using webpacker you should use "".
68
-
69
- # This configures the script to run to build the production assets by webpack . Set this to nil
70
- # if you don't want react_on_rails building this file for you.
71
- # Note, if you want to use this command then you should remove the file
72
- # config/webpack/production.js
73
- # If that file exists, React on Rails thinks that you'll use the rails/webpacker bin/webpack compiler.
74
- config.build_production_command = "RAILS_ENV=production bin/webpack"
66
+ # defaults to "" (top level)
67
+ config.node_modules_location = "client" # If using webpacker you should use "".
68
+
69
+ # If you're using the standard rails/webpacker configuration of webpack, then rails/webpacker
70
+ # will automatically modify or create an assets:precompile task to build your assets. If so,
71
+ # set this value to nil. Alternatively, you can specify `config.build_production_command`
72
+ # to have react_on_rails invoke a command for you during assets:precompile.
73
+ # The command is either a script or a module containing a class method `call`
74
+ # In this example, the module BuildProductionCommand would have a class method `call`.
75
+ config.build_production_command = "RAILS_ENV=production bin/webpacker"
76
+
77
+ # See bottom for an example of the BuildProductionCommand module.
78
+ # config.build_production_command = BuildProductionCommand
79
+ # If you wish to utilize ReactOnRailsPro production bundle caching logic, then use
80
+ # config.build_production_command = ReactOnRailsPro::AssetsPrecompile
81
+ # and be sure to check ReactOnRailsPro's configuration documentation!
75
82
 
76
83
  ################################################################################
77
84
  ################################################################################
78
85
  # SERVER RENDERING OPTIONS
79
86
  ################################################################################
80
87
  # This is the file used for server rendering of React when using `(prerender: true)`
81
- # If you are never using server rendering, you should set this to "".
88
+ # If you are not using server rendering, you should set this to `nil`.
82
89
  # Note, there is only one server bundle, unlike JavaScript where you want to minimize the size
83
90
  # of the JS sent to the client. For the server rendering, React on Rails creates a pool of
84
91
  # JavaScript execution instances which should handle any component requested.
@@ -89,9 +96,9 @@ ReactOnRails.configure do |config|
89
96
  # you should include a name that matches your bundle name in your webpack config.
90
97
  config.server_bundle_js_file = "server-bundle.js"
91
98
 
92
- # THE BELOW OPTIONS FOR SERVER-SIDE RENDERING RARELY NEED CHANGING
99
+ # THE BELOW OPTIONS FOR SERVER-SIDE RENDERING RARELY NEED CHANGING
93
100
  #
94
- # This value only affects server-side rendering when using the webpack-dev-server
101
+ # This value only affects server-side rendering when using the webpack-dev-server
95
102
  # If you are hashing the server bundle and you want to use the same bundle for client and server,
96
103
  # you'd set this to `true` so that React on Rails reads the server bundle from the webpack-dev-server.
97
104
  # Normally, you have different bundles for client and server, thus, the default is false.
@@ -101,7 +108,7 @@ ReactOnRails.configure do |config|
101
108
  # If true, ensure that in config/webpacker.yml that you have both dev_server.hmr and
102
109
  # dev_server.inline set to false.
103
110
  config.same_bundle_for_client_and_server = false
104
-
111
+
105
112
  # If set to true, this forces Rails to reload the server bundle if it is modified
106
113
  # Default value is Rails.env.development?
107
114
  # You probably will never change this.
@@ -119,16 +126,21 @@ ReactOnRails.configure do |config|
119
126
 
120
127
  # Default is true only for development? to raise exception on server if the JS code throws for
121
128
  # server rendering. The reason is that the server logs will show the error and force you to fix
122
- # any server rendering issues immediately during development.
123
- config.raise_on_prerender_error = Rails.env.development?
129
+ # any server rendering issues immediately during development.
130
+ config.raise_on_prerender_error = Rails.env.development?
131
+
132
+ # This configuration allows logic to be applied to client rendered props, such as stripping props that are only used during server rendering.
133
+ # Add a module with an adjust_props_for_client_side_hydration method that expects the component's name & props hash
134
+ # See below for an example definition of RenderingPropsExtension
135
+ config.rendering_props_extension = RenderingPropsExtension
124
136
 
125
137
  ################################################################################
126
138
  # Server Renderer Configuration for ExecJS
127
139
  ################################################################################
128
140
  # The default server rendering is ExecJS, probably using the mini_racer gem
129
- # If you wish to use an alternative Node server rendering for higher performance,
141
+ # If you wish to use an alternative Node server rendering for higher performance,
130
142
  # contact justin@shakacode.com for details.
131
- #
143
+ #
132
144
  # For ExecJS:
133
145
  # You can configure your pool of JS virtual machines and specify where it should load code:
134
146
  # On MRI, use `mini_racer` for the best performance
@@ -153,7 +165,7 @@ ReactOnRails.configure do |config|
153
165
  # By default(without this option) all yaml files from Rails.root.join("config", "locales")
154
166
  # and installed gems are loaded
155
167
  config.i18n_yml_dir = Rails.root.join("config", "locales")
156
-
168
+
157
169
  # Possible output formats are js and json
158
170
  # The default format is json
159
171
  config.i18n_output_format = 'json'
@@ -169,22 +181,21 @@ ReactOnRails.configure do |config|
169
181
 
170
182
  # You can optionally add values to your rails_context. This object is passed
171
183
  # every time a component renders.
172
- # See example below for an example definition of RenderingExtension
173
- #
174
- # config.rendering_extension = RenderingExtension
184
+ # See below for an example definition of RenderingExtension
185
+ config.rendering_extension = RenderingExtension
175
186
 
176
187
  ################################################################################
177
188
  ################################################################################
178
189
  # TEST CONFIGURATION OPTIONS
179
190
  # Below options are used with the use of this test helper:
180
191
  # ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
181
- #
192
+ #
182
193
  # NOTE:
183
194
  # Instead of using this test helper, you may ensure fresh test files using rails/webpacker via:
184
195
  # 1. Have `config/webpacker/test.js` exporting an array of objects to configure both client and server bundles.
185
196
  # 2. Set the compile option to true in config/webpacker.yml for env test
186
197
  ################################################################################
187
-
198
+
188
199
  # If you are using this in your spec_helper.rb (or rails_helper.rb):
189
200
  #
190
201
  # ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
@@ -192,9 +203,9 @@ ReactOnRails.configure do |config|
192
203
  # with rspec then this controls what yarn command is run
193
204
  # to automatically refresh your webpack assets on every test run.
194
205
  #
195
- config.build_test_command = "RAILS_ENV=test bin/webpack"
206
+ config.build_test_command = "RAILS_ENV=test bin/webpacker"
196
207
 
197
- # CONFIGURE YOUR SOURCE FILES
208
+ # CONFIGURE YOUR SOURCE FILES
198
209
  # The test helper needs to know where your JavaScript files exist. The value is configured
199
210
  # by your config/webpacker.yml source_path:
200
211
  # source_path: client/app # if using recommended /client directory
@@ -202,10 +213,33 @@ ReactOnRails.configure do |config|
202
213
  # Define the files we need to check for webpack compilation when running tests.
203
214
  # The default is `%w( manifest.json )` as will be sufficient for most webpacker builds.
204
215
  # However, if you are generated a server bundle that is NOT hashed (present in manifest.json),
205
- # then include the file in this list like this:
216
+ # then include the file in this list like this:
206
217
  config.webpack_generated_files = %w( server-bundle.js manifest.json )
207
218
  # Note, be sure NOT to include your server-bundle.js if it is hashed, or else React on Rails will
208
- # think the server-bundle.js is missing every time for test runs.
219
+ # think the server-bundle.js is missing every time for test runs.
220
+ end
221
+ ```
222
+
223
+ Example of a ReactOnRailsConfig module for `client_props_extension`:
224
+
225
+ ```ruby
226
+ module RenderingPropsExtension
227
+ # The modify_props method will be called by ReactOnRails::ReactComponent::RenderOptions if config.client_props_extension is defined
228
+ def self.adjust_props_for_client_side_hydration(component_name, props)
229
+ component_name == 'HelloWorld' ? props.except(:server_side_only) : props
230
+ end
231
+ end
232
+ ```
233
+
234
+ Example of a ReactOnRailsConfig module for `production_build_command`:
235
+
236
+ ```ruby
237
+ module BuildProductionCommand
238
+ include FileUtils
239
+ # The call method will be called during assets:precompile
240
+ def self.call
241
+ sh "bin/webpacker"
242
+ end
209
243
  end
210
244
  ```
211
245
 
@@ -0,0 +1,4 @@
1
+ # Deployment
2
+
3
+ - `rails/webpacker` puts the necessary precompile steps automatically in the rake precompile step.
4
+ - See the [Heroku Deployment](https://www.shakacode.com/react-on-rails/docs/deployment/heroku-deployment/) doc for specifics regarding Heroku. The information for Heroku may apply to other deployments.