react_on_rails 11.0.5 → 13.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +338 -0
  3. data/.eslintignore +2 -1
  4. data/.eslintrc +32 -3
  5. data/.github/FUNDING.yml +1 -0
  6. data/.github/ISSUE_TEMPLATE/bug_report.md +23 -0
  7. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  8. data/.github/PULL_REQUEST_TEMPLATE.md +19 -0
  9. data/.github/workflows/lint-js-and-ruby.yml +54 -0
  10. data/.github/workflows/main.yml +183 -0
  11. data/.github/workflows/package-js-tests.yml +35 -0
  12. data/.github/workflows/rspec-package-specs.yml +46 -0
  13. data/.gitignore +3 -4
  14. data/.prettierignore +14 -0
  15. data/.prettierrc +20 -0
  16. data/.rubocop.yml +76 -34
  17. data/.travis.yml +15 -22
  18. data/CHANGELOG.md +443 -55
  19. data/CONTRIBUTING.md +62 -80
  20. data/Gemfile +1 -35
  21. data/Gemfile.development_dependencies +50 -0
  22. data/KUDOS.md +4 -1
  23. data/{docs/LICENSE.md → LICENSE.md} +1 -1
  24. data/NEWS.md +14 -4
  25. data/REACT-ON-RAILS-PRO-LICENSE +95 -0
  26. data/README.md +107 -802
  27. data/Rakefile +1 -8
  28. data/SUMMARY.md +51 -29
  29. data/book.json +5 -5
  30. data/docs/{basics/generator.md → additional-details/generator-details.md} +5 -13
  31. data/docs/{basics/installation-overview.md → additional-details/manual-installation-overview.md} +9 -14
  32. data/docs/{basics → additional-details}/migrating-from-react-rails.md +1 -1
  33. data/docs/additional-details/recommended-project-structure.md +69 -0
  34. data/docs/additional-details/tips-for-usage-with-sp6.md +15 -0
  35. data/docs/additional-details/upgrade-webpacker-v3-to-v4.md +10 -0
  36. data/docs/api/javascript-api.md +35 -6
  37. data/docs/api/redux-store-api.md +102 -0
  38. data/docs/api/view-helpers-api.md +133 -0
  39. data/docs/contributor-info/errors-with-hooks.md +45 -0
  40. data/docs/contributor-info/linters.md +5 -6
  41. data/docs/contributor-info/pull-requests.md +42 -0
  42. data/docs/contributor-info/releasing.md +1 -1
  43. data/docs/deployment/heroku-deployment.md +39 -0
  44. data/docs/getting-started.md +196 -0
  45. data/docs/guides/client-vs-server-rendering.md +27 -0
  46. data/docs/guides/configuration.md +289 -0
  47. data/docs/guides/deployment.md +5 -0
  48. data/docs/guides/file-system-based-automated-bundle-generation.md +197 -0
  49. data/docs/guides/hmr-and-hot-reloading-with-the-webpack-dev-server.md +104 -0
  50. data/docs/guides/how-react-on-rails-works.md +44 -0
  51. data/docs/guides/how-to-conditionally-server-render-based-on-device-type.md +40 -0
  52. data/docs/guides/how-to-use-different-files-for-client-and-server-rendering.md +98 -0
  53. data/docs/guides/i18n.md +87 -0
  54. data/docs/guides/installation-into-an-existing-rails-app.md +66 -0
  55. data/docs/guides/minitest-configuration.md +31 -0
  56. data/docs/guides/rails-webpacker-react-integration-options.md +213 -0
  57. data/docs/guides/react-on-rails-overview.md +29 -0
  58. data/docs/guides/react-server-rendering.md +32 -0
  59. data/docs/guides/render-functions-and-railscontext.md +205 -0
  60. data/docs/guides/rspec-configuration.md +73 -0
  61. data/docs/guides/tutorial.md +371 -0
  62. data/docs/{basics → guides}/upgrading-react-on-rails.md +126 -3
  63. data/docs/guides/webpack-configuration.md +42 -0
  64. data/docs/home.md +23 -0
  65. data/docs/javascript/asset-pipeline.md +12 -0
  66. data/docs/{additional-reading → javascript}/code-splitting.md +21 -11
  67. data/docs/javascript/converting-from-custom-webpack-config-to-rails-webpacker-config.md +10 -0
  68. data/docs/javascript/credits.md +10 -0
  69. data/docs/{additional-reading → javascript}/images.md +5 -6
  70. data/docs/javascript/react-helmet.md +100 -0
  71. data/docs/javascript/react-router.md +90 -0
  72. data/docs/{additional-reading → javascript}/server-rendering-tips.md +15 -12
  73. data/docs/javascript/troubleshooting-when-using-shakapacker.md +77 -0
  74. data/docs/{additional-reading → javascript}/webpack.md +2 -2
  75. data/docs/misc/articles.md +20 -0
  76. data/docs/misc/doctrine.md +5 -6
  77. data/docs/outdated/deferred-rendering.md +39 -0
  78. data/docs/{additional-reading → outdated}/rails-assets-relative-paths.md +4 -4
  79. data/docs/{additional-reading → outdated}/rails-assets.md +12 -20
  80. data/docs/{misc → outdated}/rails3.md +2 -2
  81. data/docs/rails/convert-rails-5-api-only-app.md +19 -0
  82. data/docs/rails/rails-engine-integration.md +32 -0
  83. data/docs/{additional-reading → rails}/rails_view_rendering_from_inline_javascript.md +2 -1
  84. data/docs/{additional-reading → rails}/turbolinks.md +13 -1
  85. data/docs/react-on-rails-pro/react-on-rails-pro.md +43 -0
  86. data/docs/testimonials/hvmn.md +25 -0
  87. data/docs/testimonials/resortpass.md +13 -0
  88. data/docs/testimonials/testimonials.md +28 -0
  89. data/jest.config.js +4 -0
  90. data/lib/generators/USAGE +1 -1
  91. data/lib/generators/react_on_rails/adapt_for_older_shakapacker_generator.rb +41 -0
  92. data/lib/generators/react_on_rails/base_generator.rb +55 -43
  93. data/lib/generators/react_on_rails/bin/dev +30 -0
  94. data/lib/generators/react_on_rails/bin/dev-static +30 -0
  95. data/lib/generators/react_on_rails/dev_tests_generator.rb +4 -3
  96. data/lib/generators/react_on_rails/generator_helper.rb +8 -6
  97. data/lib/generators/react_on_rails/generator_messages.rb +40 -0
  98. data/lib/generators/react_on_rails/install_generator.rb +37 -0
  99. data/lib/generators/react_on_rails/templates/.eslintrc +3 -1
  100. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +4 -6
  101. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static +9 -0
  102. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +21 -40
  103. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +4 -0
  104. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorldServer.js +5 -0
  105. data/lib/generators/react_on_rails/templates/base/base/app/javascript/packs/server-bundle.js +8 -0
  106. data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb +2 -1
  107. data/lib/generators/react_on_rails/templates/base/base/babel.config.js.tt +32 -0
  108. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +20 -4
  109. data/lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml +62 -0
  110. data/lib/generators/react_on_rails/templates/base/base/config/webpack/clientWebpackConfig.js.tt +17 -0
  111. data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +17 -0
  112. data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +25 -0
  113. data/lib/generators/react_on_rails/templates/base/base/config/webpack/production.js.tt +9 -0
  114. data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt +117 -0
  115. data/lib/generators/react_on_rails/templates/base/base/config/webpack/test.js.tt +9 -0
  116. data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpack.config.js.tt +15 -0
  117. data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpackConfig.js.tt +36 -0
  118. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +8 -2
  119. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +1 -1
  120. data/lib/generators/react_on_rails/templates/dev_tests/spec/{features → system}/hello_world_spec.rb +2 -2
  121. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +6 -9
  122. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js +1 -3
  123. data/lib/react_on_rails/configuration.rb +198 -145
  124. data/lib/react_on_rails/error.rb +2 -0
  125. data/lib/react_on_rails/git_utils.rb +5 -3
  126. data/lib/react_on_rails/{react_on_rails_helper.rb → helper.rb} +201 -190
  127. data/lib/react_on_rails/json_output.rb +1 -1
  128. data/lib/react_on_rails/json_parse_error.rb +28 -0
  129. data/lib/react_on_rails/locales/base.rb +169 -0
  130. data/lib/react_on_rails/locales/to_js.rb +33 -0
  131. data/lib/react_on_rails/locales/to_json.rb +23 -0
  132. data/lib/react_on_rails/packs_generator.rb +234 -0
  133. data/lib/react_on_rails/prerender_error.rb +35 -27
  134. data/lib/react_on_rails/react_component/render_options.rb +64 -9
  135. data/lib/react_on_rails/server_rendering_js_code.rb +55 -0
  136. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +126 -76
  137. data/lib/react_on_rails/server_rendering_pool.rb +0 -1
  138. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +9 -8
  139. data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +17 -0
  140. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +13 -12
  141. data/lib/react_on_rails/test_helper.rb +24 -3
  142. data/lib/react_on_rails/utils.rb +94 -25
  143. data/lib/react_on_rails/version.rb +1 -1
  144. data/lib/react_on_rails/version_checker.rb +5 -1
  145. data/lib/react_on_rails/version_syntax_converter.rb +14 -12
  146. data/lib/react_on_rails/webpacker_utils.rb +105 -5
  147. data/lib/react_on_rails.rb +8 -2
  148. data/lib/tasks/assets.rake +28 -60
  149. data/lib/tasks/generate_packs.rake +11 -0
  150. data/lib/tasks/locale.rake +5 -4
  151. data/package-scripts.yml +49 -0
  152. data/package.json +52 -47
  153. data/rakelib/docker.rake +0 -5
  154. data/rakelib/dummy_apps.rake +5 -8
  155. data/rakelib/example_type.rb +12 -3
  156. data/rakelib/examples.rake +5 -4
  157. data/rakelib/lint.rake +5 -16
  158. data/rakelib/node_package.rake +2 -2
  159. data/rakelib/release.rake +37 -23
  160. data/rakelib/run_rspec.rake +16 -44
  161. data/rakelib/task_helpers.rb +16 -4
  162. data/react_on_rails.gemspec +6 -22
  163. data/tsconfig.json +14 -0
  164. data/webpackConfigLoader.js +5 -4
  165. data/yarn.lock +5935 -3106
  166. metadata +122 -272
  167. data/Gemfile.rails32 +0 -74
  168. data/docs/additional-reading/asset-pipeline.md +0 -20
  169. data/docs/additional-reading/babel.md +0 -5
  170. data/docs/additional-reading/caching-and-performance.md +0 -4
  171. data/docs/additional-reading/heroku-deployment.md +0 -92
  172. data/docs/additional-reading/hot-reloading-rails-development.md +0 -57
  173. data/docs/additional-reading/node-server-rendering.md +0 -5
  174. data/docs/additional-reading/rails-engine-integration.md +0 -34
  175. data/docs/additional-reading/react-helmet.md +0 -80
  176. data/docs/additional-reading/react-router.md +0 -113
  177. data/docs/additional-reading/recommended-project-structure.md +0 -49
  178. data/docs/additional-reading/rspec-configuration.md +0 -56
  179. data/docs/additional-reading/webpack-dev-server.md +0 -15
  180. data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
  181. data/docs/api/ruby-api.md +0 -8
  182. data/docs/basics/configuration.md +0 -163
  183. data/docs/basics/i18n.md +0 -77
  184. data/docs/tutorial.md +0 -220
  185. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +0 -12
  186. data/lib/react_on_rails/assets_precompile.rb +0 -150
  187. data/lib/react_on_rails/locales_to_js.rb +0 -134
  188. data/ruby-lint.yml +0 -25
  189. /data/docs/{additional-reading → additional-details}/updating-dependencies.md +0 -0
  190. /data/docs/{additional-reading → deployment}/elastic-beanstalk.md +0 -0
  191. /data/docs/{additional-reading → javascript}/angular-js-integration-migration.md +0 -0
  192. /data/docs/{additional-reading → javascript}/capistrano-deployment.md +0 -0
  193. /data/docs/{additional-reading → javascript}/foreman-issues.md +0 -0
  194. /data/docs/{additional-reading → javascript}/node-dependencies-and-npm.md +0 -0
  195. /data/docs/{additional-reading → javascript}/react-and-redux.md +0 -0
  196. /data/docs/{additional-reading → javascript}/troubleshooting-when-using-webpacker.md +0 -0
  197. /data/docs/{additional-reading → javascript}/webpack-v1-notes.md +0 -0
  198. /data/docs/{coding-style → misc}/style.md +0 -0
  199. /data/docs/{additional-reading → misc}/tips.md +0 -0
data/Rakefile CHANGED
@@ -3,9 +3,7 @@
3
3
  # Rake will automatically load any *.rake files inside of the "rakelib" folder
4
4
  # See rakelib/
5
5
 
6
- require_relative "./spec/react_on_rails/support/rails32_helper"
7
-
8
- tasks = %w[run_rspec lint]
6
+ tasks = %w[lint run_rspec]
9
7
  prepare_for_ci = %w[node_package dummy_apps]
10
8
 
11
9
  if ENV["USE_COVERALLS"] == "TRUE"
@@ -14,11 +12,6 @@ if ENV["USE_COVERALLS"] == "TRUE"
14
12
  tasks << "coveralls:push"
15
13
  end
16
14
 
17
- if using_rails32?
18
- tasks = %w[run_rspec:gem_rails32 run_rspec:dummy_no_webpacker]
19
- prepare_for_ci = %w[node_package dummy_apps:dummy_no_webpacker]
20
- end
21
-
22
15
  desc "Run all tests and linting"
23
16
  task default: tasks
24
17
 
data/SUMMARY.md CHANGED
@@ -1,50 +1,72 @@
1
- # Table of Content
1
+ # Table of Contents
2
2
 
3
- ### **Rails**
4
- + [Rails Assets](./docs/additional-reading/rails-assets.md)
3
+ Doccumentation for React on Rails has moved!
4
+
5
+ Here is the new link:
6
+
7
+ **[React on Rails Documentation Link](https://www.shakacode.com/react-on-rails/docs/)**
8
+
9
+ -----
10
+
11
+ ## **OLD DOCS BELOW**
12
+ + [Home](./README.md)
13
+
14
+ ## **Basics**
15
+ + [React on Rails Basic Installation Tutorial](./docs/tutorial.md)
16
+ + [Webpack Configuration](./docs/guides/webpack-configuration.md)
17
+ + [How React on Rails Works](docs/outdated/how-react-on-rails-works.md)
18
+ + [Client vs. Server Rendering](./docs/guides/client-vs-server-rendering.md)
19
+ + [React Server Rendering](./docs/guides/react-server-rendering.md)
20
+ + [Render-Functions and the RailsContext](docs/guides/render-functions-and-railscontext.md)
21
+ + [Caching and Performance: React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki).
22
+ + [Deployment](docs/guides/deployment.md).
23
+ + [React on Rails Internationalization (I18n, localization)](docs/guides/i18n.md)
24
+ + [RSpec Test Helpers Configuration](docs/guides/rspec-configuration.md)
25
+ + [Minitest Configuration](docs/guides/minitest-configuration.md)
26
+ + [Upgrading React on Rails](docs/guides/upgrading-react-on-rails.md)
27
+
28
+ ## **API**
29
+ - [View Helpers API](./docs/api/view-helpers-api.md)
30
+ - [JavaScript API](./docs/api/javascript-api.md)
31
+ - [Redux Store API](./docs/api/redux-store-api.md)
32
+
33
+ ## **Additional Details**
34
+ + [Migration from react-rails](./docs/guides/migrating-from-react-rails.md)
35
+ + [Generator Details](docs/guides/generator-details.md)
36
+ + [Updating Dependencies](./docs/additional-reading/updating-dependencies.md)
37
+ + [Manual Installation Overview](docs/outdated/manual-installation-overview.md)
38
+ + [Upgrading from rails/webpacker v3 to v4](docs/additional-reading/upgrade-webpacker-v3-to-v4.md)
39
+ + [Recommended Project Structure](docs/additional-reading/recommended-project-structure.md)
40
+
41
+ ## **Rails**
5
42
  + [Rails Engine Integration](./docs/additional-reading/rails-engine-integration.md)
6
43
  + [Rails View Rendering from Inline JavaScript](./docs/additional-reading/rails_view_rendering_from_inline_javascript.md)
7
- + [RSpec Configuration](./docs/additional-reading/rspec-configuration.md)
8
44
  + [Turbolinks](./docs/additional-reading/turbolinks.md)
9
- + [React on Rails Internationalization (I18n)](https://github.com/shakacode/react_on_rails/blob/master/docs/basics/i18n.md)
45
+ + [Converting a Rails 5 API only app to a Rails app](./docs/additional-reading/convert-rails-5-api-only-app.md)
10
46
 
11
- ### **Javascript**
47
+ ## **Javascript**
12
48
  + [Node Dependencies, NPM, and Yarn](./docs/additional-reading/node-dependencies-and-npm.md)
13
- + [Babel](./docs/additional-reading/babel.md)
14
49
  + [React Router](./docs/additional-reading/react-router.md)
15
50
  + [React & Redux](./docs/additional-reading/react-and-redux.md)
16
- + [Webpack](./docs/additional-reading/webpack.md)
17
- + [Webpack Configuration](./docs/additional-reading/webpack.md)
18
- + [Webpack Cookbook](https://christianalfoni.github.io/react-webpack-cookbook/index.html)
19
- + [Developing with the Webpack Dev Server](docs/additional-reading/webpack-dev-server.md)
20
- + [Node Server Rendering](./docs/additional-reading/node-server-rendering.md)
51
+ + [Webpack Tips](./docs/additional-reading/webpack.md)
21
52
  + [Server Rendering Tips](./docs/additional-reading/server-rendering-tips.md)
22
- + [Code Splitting](./docs/additional-reading/code-splitting.md)
53
+ + [Code Splitting](docs/outdated/code-splitting.md)
23
54
  + [AngularJS Integration and Migration to React on Rails](./docs/additional-reading/angular-js-integration-migration.md)
24
- + [Webpack, the Asset Pipeline, and Using Assets w/ React](./docs/additional-reading/rails-assets-relative-paths.md)
25
55
 
26
- ### **Development**
27
- + [React on Rails Basic Installation Tutorial](./docs/tutorial.md)
28
- + [Installation Overview](./docs/basics/installation-overview.md)
29
- + [Migration from react-rails](./docs/basics/migrating-from-react-rails.md)
30
- + [Recommended Project Structure](./docs/additional-reading/recommended-project-structure.md)
31
- + [Generator Tips](./docs/basics/generator.md)
32
- + [Hot Reloading of Assets For Rails Development](./docs/additional-reading/hot-reloading-rails-development.md)
33
- + [Heroku Deployment](./docs/additional-reading/heroku-deployment.md)
56
+ ## **Deployment**
57
+ + [Heroku Deployment](docs/guides/heroku-deployment.md)
34
58
  + [Elastic Beanstalk Deployment](./docs/additional-reading/elastic-beanstalk.md)
35
- + [Updating Dependencies](./docs/additional-reading/updating-dependencies.md)
36
59
 
37
- ### **API**
38
- + [JavaScript API](./docs/api/javascript-api.md)
39
- + [Ruby API](./docs/api/ruby-api.md)
40
- + [Setting up Hot Reloading during Rails Development, API docs](./docs/api/ruby-api-hot-reload-view-helpers.md)
60
+ ## Outdated Non-Webpack Docs
61
+ + [Developing with the Webpack Dev Server](./docs/additional-reading/webpack-dev-server.md)
62
+ + [Webpack, the Asset Pipeline, and Using Assets w/ React](./docs/outdated/rails-assets-relative-paths.md)
41
63
 
42
- ### **[CONTRIBUTING](CONTRIBUTING.md)**
64
+ ## **[CONTRIBUTING](CONTRIBUTING.md)**
43
65
  + [Generator Testing](./docs/contributor-info/generator-testing.md)
44
66
  + [Linting](./docs/contributor-info/linters.md)
45
67
  + [Releasing](./docs/contributor-info/releasing.md)
46
68
 
47
- ### **Misc**
69
+ ## **Misc**
48
70
  + [Tips](./docs/additional-reading/tips.md)
49
71
  + [Changelog](./CHANGELOG.md)
50
72
  + [Projects](./PROJECTS.md)
data/book.json CHANGED
@@ -7,12 +7,12 @@
7
7
  "url": "https://github.com/shakacode/react_on_rails/"
8
8
  },
9
9
  "sharing": {
10
- "facebook": true,
11
- "twitter": true,
12
- "google": true,
13
- "weibo": true,
10
+ "facebook": true,
11
+ "twitter": true,
12
+ "google": true,
13
+ "weibo": true,
14
14
  "instapaper": true,
15
- "vk": true
15
+ "vk": true
16
16
  }
17
17
  }
18
18
  }
@@ -1,7 +1,4 @@
1
- - [Generator](#generator)
2
- - [Understanding the Organization of the Generated Client Code](#understanding-the-organization-of-the-generated-client-code)
3
- - [Redux](#redux)
4
- - [Using Images and Fonts](#using-images-and-fonts)
1
+ # Generator Details
5
2
 
6
3
  The `react_on_rails:install` generator combined with the example pull requests of generator runs will get you up and running efficiently. There's a fair bit of setup with integrating Webpack with Rails. Defaults for options are such that the default is for the flag to be off. For example, the default for `-R` is that `redux` is off, and the default of `-b` is that `skip-bootstrap` is off.
7
4
 
@@ -38,16 +35,12 @@ can pass the redux option if you'd like to have redux setup for you automaticall
38
35
  Then you may run
39
36
 
40
37
  `rails s`
41
-
42
- More Details:
43
-
44
- `https://github.com/shakacode/react_on_rails/blob/master/docs/basics/generator.md`
45
38
  ```
46
39
 
47
- Another good option is to create a simple test app per the [Tutorial](../tutorial.md).
40
+ Another good option is to create a simple test app per the [Tutorial](https://www.shakacode.com/react-on-rails/docs/guides/tutorial/).
48
41
 
49
- ### Understanding the Organization of the Generated Client Code
50
- 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*.
42
+ # Understanding the Organization of the Generated Client Code
43
+ 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*.
51
44
 
52
45
  Inside of the generated "HelloWorld" domain you will find the following folders:
53
46
 
@@ -57,8 +50,7 @@ Inside of the generated "HelloWorld" domain you will find the following folders:
57
50
 
58
51
  You may also notice the `app/lib` folder. This is for any code that is common between bundles and therefore needs to be shared (for example, middleware).
59
52
 
60
- ### Redux
53
+ ## Redux
61
54
  If you have used the `--redux` generator option, you will notice the familiar additional redux folders in addition to the aforementioned folders. The Hello World example has also been modified to use Redux.
62
55
 
63
56
  Note the organizational paradigm of "bundles". These are like application domains and are used for grouping your code into webpack bundles, in case you decide to create different bundles for deployment. This is also useful for separating out logical parts of your application. The concept is that each bundle will have it's own Redux store. If you have code that you want to reuse across bundles, including components and reducers, place them under `/client/app/lib`.
64
-
@@ -1,17 +1,12 @@
1
- # Installation Overview
1
+ # Manual Installation Overview
2
2
 
3
- Here's an overview of installation if you're not using the generator.
3
+ TODO: Review this file
4
4
 
5
- Note, the best way to understand how to use ReactOnRails is to study the examples:
6
5
 
7
- 1. Run the generator per the [Tutorial](../tutorial.md).
8
- 2. [spec/dummy](../../spec/dummy): Simple, no DB example.
9
- 3. [github.com/shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial): Full featured example.
6
+ This file summarizes what the React on Rails generator does.
10
7
 
11
8
  ## Configure the `/client` Directory
12
9
 
13
- Note, version 9.0 of React on Rails removed the requirement to place all client side files in the `/client` directory.
14
-
15
10
  This directory has no references to Rails outside of the destination directory for the files created by the various Webpack config files.
16
11
 
17
12
  The only requirements within this directory for basic React on Rails integration are:
@@ -19,17 +14,17 @@ The only requirements within this directory for basic React on Rails integration
19
14
  1. Your webpack configuration files:
20
15
  1. Create outputs in a directory like `/public/webpack`, which is customizable in your `config/initializers/react_on_rails.rb`.
21
16
  1. Provide server rendering if you wish to use that feature.
22
- 1. Your JavaScript code "registers" any components and stores per the ReactOnRails APIs of ReactOnRails.register(components) and ReactOnRails.registerStore(stores). See API docs in [README.md](../../README.md) and the [ReactOnRails.js source](../../node_package/src/ReactOnRails.js).
17
+ 1. Your JavaScript code "registers" any components and stores per the ReactOnRails APIs of ReactOnRails.register(components) and ReactOnRails.registerStore(stores). See [our javascript API docs](https://www.shakacode.com/react-on-rails/docs/api/javascript-api/) and the [ReactOnRails.js source](https://github.com/shakacode/react_on_rails/tree/master/node_package/src/ReactOnRails.js).
23
18
  1. Set your registration file as an "entry" point in your Webpack configs.
24
- 1. Add the [Manifest plugin](https://github.com/danethurber/webpack-manifest-plugin) to your config. For examples see [dummy config](../../spec/dummy/client/webpack.client.base.config.js).
19
+ 1. Add the [Manifest plugin](https://github.com/danethurber/webpack-manifest-plugin) to your config.
25
20
  The default path: `public/webpack` can be loaded with webpackConfigLoader as shown in the dummy example.
26
21
  1. You create scripts in `client/package.json` per the example apps. These are used for building your Webpack assets. Also do this for your top level `package.json`.
27
22
 
28
23
  ## Rails Steps (outside of /client)
29
- 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)
30
- 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.
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](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/app/views/layouts/application.html.erb)
25
+ 1. Configure the `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [https://github.com/shakacode/react_on_rails/tree/master/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) for a detailed example of configuration, including comments on the different values to configure.
31
26
  1. Configure your Procfiles per the example apps. These are at the root of your Rails installation.
32
- 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)
33
- 1. If you are deploying to Heroku, see [heroku-deployment.md](/docs/additional-reading/heroku-deployment.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.
28
+ 1. If you are deploying to Heroku, see [our heroku deployment documentation](https://www.shakacode.com/react-on-rails/docs/deployment/heroku-deployment/)
34
29
 
35
30
  If I missed anything, please submit a PR or file an issue.
@@ -11,7 +11,7 @@ If you are using [react-rails](https://github.com/reactjs/react-rails) in your p
11
11
  //= require components
12
12
  ```
13
13
 
14
- - Follow our getting started guide: https://github.com/shakacode/react_on_rails#getting-started.
14
+ - Follow our [getting started guide](https://www.shakacode.com/react-on-rails/docs/getting-started/).
15
15
 
16
16
  Note: If you have components from react-rails you want to use, then you will need to port them into react_on_rails which uses webpack instead of the asset pipeline.
17
17
 
@@ -0,0 +1,69 @@
1
+ # Recommended Project structure
2
+
3
+ The React on Rails generator uses the standard Shakapacker 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_demo_ssr_hmr](https://github.com/shakacode/react_on_rails_demo_ssr_hmr),
16
+ you should consider keeping your codebase mostly consistent with the defaults for [Shakapacker](https://github.com/shakacode/shakapacker).
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/shakapacker.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
+ Shakapacker 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 `SHAKAPACKER_CONFIG` to the location of the `config/shakapacker.yml` file per [rails/webpacker PR 2561](https://github.com/rails/webpacker/pull/2561). (Notice the change of spelling from Webpacker to Shakapacker)
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,15 @@
1
+ # Tips for usage with Shakapacker 6
2
+
3
+ As mentioned earlier in the documentation, we assume you install ReactOnRails in a project with Shakapacker 7+ installed and configured. If you still use Shakapacker 6, we encourage you to check the upgrade to the version 7 guide. Otherwise, you need to consider the following:
4
+
5
+ 1. The install generator tries to take the necessary steps to adapt the installed files to match the file structure and configurations for Shakapacker 6. So you don't need to be worried about the ReactOnRails installation process.
6
+
7
+ 2. Check the following table to map the references in the documentation to the relevant ones in Shakapacker 6:
8
+
9
+ |Usage in Shakapacker 7 |Equivalant in Shakapacker 6|
10
+ |----------------------------|---------------------------|
11
+ |`config/shakapacker.yml` |`config/webpacker.yml` |
12
+ |`bin/shakapacker` |`bin/webpacker` |
13
+ |`bin/shakapacker-dev-server`|`bin/webpacker-dev-server` |
14
+
15
+ 3. Any environment variables starting with `SHAKAPACKER_*` should be changed to `WEBPACKER_*`.
@@ -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).
@@ -1,20 +1,40 @@
1
1
  # ReactOnRails JavaScript API
2
- The best source of docs is the main [ReactOnRails.js](../../node_package/src/ReactOnRails.js) file. Here's a quick summary. No guarantees that this won't be outdated!
2
+ ## CSRF protection
3
+
4
+ Rails has built-in protection for Cross-Site Request Forgery (CSRF), see [Rails Documentation](http://guides.rubyonrails.org/security.html#cross-site-request-forgery-csrf). To nicely utilize this feature in JavaScript requests, React on Rails provides two helpers that can be used as following for POST, PUT or DELETE requests:
5
+
6
+ ```js
7
+ import ReactOnRails from 'react-on-rails';
8
+
9
+ // reads from DOM csrf token generated by Rails in <%= csrf_meta_tags %>
10
+ csrfToken = ReactOnRails.authenticityToken();
11
+
12
+ // compose Rails specific request header as following { X-CSRF-Token: csrfToken, X-Requested-With: XMLHttpRequest }
13
+ header = ReactOnRails.authenticityHeaders(otherHeader);
14
+ ```
15
+
16
+ If you are using [jquery-ujs](https://github.com/rails/jquery-ujs) for AJAX calls, then these helpers are not needed because the [jquery-ujs](https://github.com/rails/jquery-ujs) library updates header automatically, see [jquery-ujs documentation](https://robots.thoughtbot.com/a-tour-of-rails-jquery-ujs#cross-site-request-forgery-protection).
17
+
18
+
19
+
20
+ ## API
21
+
22
+ The best source of docs is the main [ReactOnRails.js](https://github.com/shakacode/react_on_rails/node_package/src/ReactOnRails.js) file. Here's a quick summary. No guarantees that this won't be outdated!
3
23
 
4
24
  ```js
5
25
  /**
6
26
  * Main entry point to using the react-on-rails npm package. This is how Rails will be able to
7
27
  * find you components for rendering. Components get called with props, or you may use a
8
- * "generator function" to return a React component or an object with the following shape:
28
+ * "Render-Function" to return a React component or an object with the following shape:
9
29
  * { renderedHtml, redirectLocation, error }.
10
- * For server rendering, if you wish to return multiple HTML strings from a generator function,
11
- * you may return an Object from your generator function with a single top level property of
30
+ * For server rendering, if you wish to return multiple HTML strings from a Render-Function,
31
+ * you may return an Object from your Render-Function with a single top level property of
12
32
  * renderedHtml. Inside this Object, place a key called componentHtml, along with any other
13
33
  * needed keys. This is useful when you using side effects libraries like react helmet.
14
34
  * Your Ruby code with get this Object as a Hash containing keys componentHtml and any other
15
35
  * custom keys that you added:
16
36
  * { renderedHtml: { componentHtml, customKey1, customKey2 } }
17
- * 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
18
38
  * @param components (key is component name, value is component)
19
39
  */
20
40
  register(components)
@@ -38,6 +58,15 @@ The best source of docs is the main [ReactOnRails.js](../../node_package/src/Rea
38
58
  */
39
59
  getStore(name, throwIfMissing = true )
40
60
 
61
+ /**
62
+ * Renders or hydrates the react element passed. In case react version is >=18 will use the new api.
63
+ * @param domNode
64
+ * @param reactElement
65
+ * @param hydrate if true will perform hydration, if false will render
66
+ * @returns {Root|ReactComponent|ReactElement|null}
67
+ */
68
+ reactHydrateOrRender(domNode, reactElement, hydrate)
69
+
41
70
  /**
42
71
  * Set options for ReactOnRails, typically before you call ReactOnRails.register
43
72
  * Available Options:
@@ -49,7 +78,7 @@ The best source of docs is the main [ReactOnRails.js](../../node_package/src/Rea
49
78
  * Allow directly calling the page loaded script in case the default events that trigger react
50
79
  * rendering are not sufficient, such as when loading JavaScript asynchronously with TurboLinks:
51
80
  * More details can be found here:
52
- * https://github.com/shakacode/react_on_rails/blob/master/docs/additional-reading/turbolinks.md
81
+ * https://www.shakacode.com/react-on-rails/docs/rails/turbolinks
53
82
  */
54
83
  reactOnRailsPageLoaded()
55
84
 
@@ -0,0 +1,102 @@
1
+ # Redux Store
2
+
3
+ _This redux API is no longer recommended as it prevents dynamic code splitting for performance. Instead, you should use the standard react_component view helper passing in a "Render-Function."_
4
+
5
+ You don't need to use the `redux_store` api to use redux. This api was setup to support multiple calls to `react_component` on one page that all talk to the same redux store.
6
+
7
+ If you are only rendering one react component on a page, as is typical to do a "Single Page App" in React, then you should _probably_ pass the props to your React component in a "Render-Function."
8
+
9
+ Consider using the `redux_store` helper for the two following use cases:
10
+
11
+ 1. You want to have multiple React components accessing the same store at once.
12
+ 2. You want to place the props to hydrate the client side stores at the very end of your HTML, probably server rendered, so that the browser can render all earlier HTML first. This is particularly useful if your props will be large. However, you're probably better off using [React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki) if you're at all concerned about performance.
13
+
14
+ ## Multiple React Components on a Page with One Store
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.
17
+
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
+
20
+ Suppose the Redux store is called `appStore`, and you have 3 React components that each needs to connect to a store: `NavbarApp`, `CommentsApp`, and `BlogsApp`. I named them with `App` to indicate that they are the registered components.
21
+
22
+ You will need to make a function that can create the store you will be using for all components and register it via the `registerStore` method. Note: this is a **storeCreator**, meaning that it is a function that takes (props, location) and returns a store:
23
+
24
+ ```js
25
+ function appStore(props, railsContext) {
26
+ // Create a hydrated redux store, using props and the railsContext (object with
27
+ // Rails contextual information).
28
+ return myAppStore;
29
+ }
30
+
31
+ ReactOnRails.registerStore({
32
+ appStore
33
+ });
34
+ ```
35
+
36
+ When registering your component with React on Rails, you can get the store via `ReactOnRails.getStore`:
37
+
38
+ ```js
39
+ // getStore will initialize the store if not already initialized, so creates or retrieves store
40
+ const appStore = ReactOnRails.getStore("appStore");
41
+ return (
42
+ <Provider store={appStore}>
43
+ <CommentsApp />
44
+ </Provider>
45
+ );
46
+ ```
47
+
48
+ From your Rails view, you can use the provided helper `redux_store(store_name, props)` to create a fresh version of the store (because it may already exist if you came from visiting a previous page). Note: for this example, since we're initializing this from the main layout, we're using a generic name of `@react_props`. In other words, the Rails controller would set `@react_props` to the properties to hydrate the Redux store.
49
+
50
+ **app/views/layouts/application.html.erb**
51
+
52
+ ```erb
53
+ ...
54
+ <%= redux_store("appStore", props: @react_props) %>;
55
+ <%= react_component("NavbarApp") %>
56
+ yield
57
+ ...
58
+ ```
59
+
60
+ Components should be created as [stateless function(al) components](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions). Since you can pass in initial props via the helper `redux_store`, you do not need to pass any props directly to the component. Instead, the component hydrates by connecting to the store.
61
+
62
+ **_comments.html.erb**
63
+
64
+ ```erb
65
+ <%= react_component("CommentsApp") %>
66
+ ```
67
+
68
+ **_blogs.html.erb**
69
+
70
+ ```erb
71
+ <%= react_component("BlogsApp") %>
72
+ ```
73
+
74
+ *Note:* You will not be doing any partial updates to the Redux store when loading a new page. When the page content loads, React on Rails will rehydrate a new version of the store with whatever props are placed on the page.
75
+
76
+ ## Controller Extension
77
+
78
+ Include the module `ReactOnRails::Controller` in your controller, probably in ApplicationController. This will provide the following controller method, which you can call in your controller actions:
79
+
80
+ `redux_store(store_name, props: {})`
81
+
82
+ - **store_name:** A name for the store. You'll refer to this name in 2 places in your JavaScript:
83
+ 1. You'll call `ReactOnRails.registerStore({storeName})` in the same place that you register your components.
84
+ 2. In your component definition, you'll call `ReactOnRails.getStore('storeName')` to get the hydrated Redux store to attach to your components.
85
+ - **props:** Named parameter `props`. ReactOnRails takes care of setting up the hydration of your store with props from the view.
86
+
87
+ For an example, see [spec/dummy/app/controllers/pages_controller.rb](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/app/controllers/pages_controller.rb). Note: this is preferable to using the equivalent view_helper `redux_store` in that you can be assured that the store is initialized before your components.
88
+
89
+ ## View Helper
90
+
91
+ `redux_store(store_name, props: {})`
92
+
93
+ This method has the same API as the controller extension. **HOWEVER**, we recommend the controller extension instead because the Rails executes the template code in the controller action's view file (`erb`, `haml`, `slim`, etc.) before the layout. So long as you call `redux_store` at the beginning of your action's view file, this will work. However, it's an easy mistake to put this call in the wrong place. Calling `redux_store` in the controller action ensures proper load order, regardless of where you call this in the controller action. Note: you won't know of this subtle ordering issue until you server render and you find that your store is not hydrated properly.
94
+
95
+ `redux_store_hydration_data`
96
+
97
+ Place this view helper (no parameters) at the end of your shared layout so ReactOnRails will render the redux store hydration data. Since we're going to be setting up the stores in the controllers, we need to know where on the view to put the client-side rendering of this hydration data, which is a hidden div with a matching class that contains a data props. For an example, see [spec/dummy/app/views/layouts/application.html.erb](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/app/views/layouts/application.html.erb).
98
+
99
+ # More Details
100
+
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