react_on_rails 11.3.0 → 12.0.0.pre.beta.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +320 -0
  3. data/.eslintignore +2 -1
  4. data/.eslintrc +23 -1
  5. data/.github/FUNDING.yml +1 -0
  6. data/.gitignore +3 -1
  7. data/.prettierignore +10 -1
  8. data/.prettierrc +3 -0
  9. data/.rubocop.yml +37 -11
  10. data/.travis.yml +9 -22
  11. data/CHANGELOG.md +65 -6
  12. data/CONTRIBUTING.md +60 -71
  13. data/Gemfile +3 -4
  14. data/{COMM-LICENSE → REACT-ON-RAILS-PRO-LICENSE} +6 -9
  15. data/README.md +129 -92
  16. data/Rakefile +0 -7
  17. data/SUMMARY.md +7 -11
  18. data/book.json +5 -5
  19. data/docs/additional-reading/asset-pipeline.md +8 -16
  20. data/docs/additional-reading/react-helmet.md +30 -10
  21. data/docs/additional-reading/react-router.md +52 -75
  22. data/docs/additional-reading/server-rendering-tips.md +12 -7
  23. data/docs/api/javascript-api.md +3 -3
  24. data/docs/api/redux-store-api.md +4 -2
  25. data/docs/api/view-helpers-api.md +6 -7
  26. data/docs/basics/configuration.md +83 -69
  27. data/docs/basics/deployment.md +2 -4
  28. data/docs/basics/heroku-deployment.md +24 -0
  29. data/docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md +49 -0
  30. data/docs/basics/i18n.md +45 -23
  31. data/docs/basics/installation-into-an-existing-rails-app.md +4 -9
  32. data/docs/basics/react-server-rendering.md +1 -1
  33. data/docs/basics/recommended-project-structure.md +5 -22
  34. data/docs/basics/{generator-functions-and-railscontext.md → render-functions-and-railscontext.md} +59 -21
  35. data/docs/basics/rspec-configuration.md +27 -16
  36. data/docs/basics/upgrading-react-on-rails.md +58 -2
  37. data/docs/basics/webpack-configuration.md +18 -8
  38. data/docs/contributor-info/errors-with-hooks.md +45 -0
  39. data/docs/contributor-info/pull-requests.md +44 -0
  40. data/docs/misc/doctrine.md +1 -1
  41. data/docs/{misc-pending → outdated}/code-splitting.md +12 -8
  42. data/docs/{basics → outdated}/how-react-on-rails-works.md +8 -4
  43. data/docs/{misc-pending → outdated}/manual-installation-overview.md +5 -5
  44. data/docs/{additional-reading → outdated}/rails-assets-relative-paths.md +3 -3
  45. data/docs/{misc-pending → outdated}/rails-assets.md +2 -12
  46. data/docs/{misc → outdated}/rails3.md +0 -0
  47. data/docs/tutorial.md +94 -68
  48. data/jest.config.js +4 -0
  49. data/lib/generators/react_on_rails/base_generator.rb +2 -2
  50. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
  51. data/lib/generators/react_on_rails/generator_helper.rb +4 -6
  52. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +3 -1
  53. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr +26 -0
  54. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +20 -40
  55. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +4 -1
  56. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +4 -8
  57. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js +1 -3
  58. data/lib/react_on_rails.rb +3 -1
  59. data/lib/react_on_rails/configuration.rb +58 -28
  60. data/lib/react_on_rails/error.rb +2 -0
  61. data/lib/react_on_rails/helper.rb +41 -91
  62. data/lib/react_on_rails/json_parse_error.rb +2 -0
  63. data/lib/react_on_rails/locales/base.rb +150 -0
  64. data/lib/react_on_rails/locales/to_js.rb +37 -0
  65. data/lib/react_on_rails/locales/to_json.rb +27 -0
  66. data/lib/react_on_rails/prerender_error.rb +11 -15
  67. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +41 -46
  68. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +7 -8
  69. data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +17 -0
  70. data/lib/react_on_rails/utils.rb +14 -19
  71. data/lib/react_on_rails/version.rb +1 -1
  72. data/lib/react_on_rails/version_checker.rb +1 -0
  73. data/lib/react_on_rails/webpacker_utils.rb +19 -2
  74. data/lib/tasks/assets.rake +33 -46
  75. data/lib/tasks/locale.rake +4 -2
  76. data/package-scripts.yml +11 -8
  77. data/package.json +29 -28
  78. data/rakelib/dummy_apps.rake +1 -9
  79. data/rakelib/example_type.rb +3 -1
  80. data/rakelib/examples.rake +3 -0
  81. data/rakelib/lint.rake +2 -7
  82. data/rakelib/node_package.rake +2 -2
  83. data/rakelib/release.rake +0 -6
  84. data/rakelib/run_rspec.rake +5 -18
  85. data/react_on_rails.gemspec +4 -5
  86. data/tsconfig.json +14 -0
  87. data/webpackConfigLoader.js +3 -2
  88. data/yarn.lock +4333 -2209
  89. metadata +46 -57
  90. data/Gemfile.rails32 +0 -73
  91. data/docs/additional-reading/babel.md +0 -5
  92. data/docs/additional-reading/heroku-deployment.md +0 -92
  93. data/docs/additional-reading/hot-reloading-rails-development-asset-pipeline.md +0 -47
  94. data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
  95. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +0 -12
  96. data/lib/react_on_rails/assets_precompile.rb +0 -153
  97. data/lib/react_on_rails/locales_to_js.rb +0 -138
@@ -3,12 +3,10 @@ sudo: required
3
3
  language: ruby
4
4
 
5
5
  rvm:
6
- # Rails 5 requires 2.2
7
- - 2.3.8
8
- - 2.4.5
9
6
  - 2.5.3
10
- - 2.6.0
11
- - 2.2.10
7
+ - 2.6.5
8
+ - 2.7.0
9
+
12
10
  services:
13
11
  - docker
14
12
 
@@ -20,7 +18,6 @@ cache:
20
18
 
21
19
  gemfile:
22
20
  - spec/dummy/Gemfile
23
- - spec/dummy_no_webpacker/Gemfile.rails32
24
21
 
25
22
  env:
26
23
  global:
@@ -37,13 +34,16 @@ before_install:
37
34
  - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen scn 1600x1200x16"
38
35
 
39
36
  install:
40
- - travis_retry gem install bundler -v '<2' # Ruby 2.2 and Rails 3.2 & 4.2 depend on bundler 1.x.
41
- - travis_retry nvm install 8.11.3
37
+ - travis_retry gem install bundler -v '>2'
38
+ - travis_retry nvm install 13.9.0
42
39
  - node -v
43
40
  - travis_retry npm i -g yarn
44
41
  - travis_retry bundle install
42
+ - travis_retry yarn global add yalc
43
+ - travis_retry yalc publish
44
+ - travis_retry cd spec/dummy && yalc add react-on-rails
45
45
  - travis_retry yarn
46
- - travis_retry yarn run build
46
+ - travis_retry cd ../.. && yarn run build
47
47
  - bundle exec rake prepare_for_ci
48
48
 
49
49
  before_script:
@@ -52,19 +52,6 @@ before_script:
52
52
  script:
53
53
  - bundle exec rake
54
54
 
55
- matrix:
56
- exclude:
57
- - gemfile: spec/dummy_no_webpacker/Gemfile.rails32
58
- rvm: 2.3.8
59
- - gemfile: spec/dummy_no_webpacker/Gemfile.rails32
60
- rvm: 2.4.5
61
- - gemfile: spec/dummy_no_webpacker/Gemfile.rails32
62
- rvm: 2.5.3
63
- - gemfile: spec/dummy_no_webpacker/Gemfile.rails32
64
- rvm: 2.6.0
65
- - gemfile: spec/dummy/Gemfile
66
- rvm: 2.2.10
67
-
68
55
  notifications:
69
56
  slack:
70
57
  secure: LfcUk4AJ4vAxWwRIyw4tFh8QNbYefMwfG/oLfsN3CdRMWMOtCOHR1GGsRhAOlfVVJ/FvHqVqWj5gK7z7CaO5Uvl7rD3/zJ8QzExKx/iH9yWj55iIPuKLzwFNnBwRpFW/cqyU2lFPPRxGD50BUn3c+qybkuSqtKZ6qtTowwqlxLa5iyM3N95aZp7MEIKCP7cPcnHfLbJyP8wBpotp/rtw62eXM2HIRJJwgjcp+n+My7VFR9DnBXNFf6R91aZHM4U4cHHDbu15HFtH8honVrzK1JQdyqMNHga+j04dFuaS7z9Q369/hsELMOBp/227+Pz7ZRfWZFK4UASguOvyeX7RmGTRpTuWLm1XJeUzfsPZVROecaSVQBve+U7F12yKqilt97QlvRXn2EGyBILqvxtFNNR4S9kgAf72/6EFgiM1TKq7i9zy6lVOnagU2+7amq7UeopX1uoFsUfNKMR7YbgV1WjF0IK95UP0b0/7ZOJlPYgi5zzkQi129qAFWSMmxGk+ZpsttHh/tjJtvAh0A3mHq/zb5w4ub/MbSyZqeDUNgGj72QArOWUFSAStQT1ybsVLeDoKPgOvVq7OV1D64rpcHjBXcqOCit8tDZ+TqkFhcYJo2cITSaqE4zJXn+4F5s7So5O8CyfKYQq+kFJCooYGmfgTUckJpGl7eIvKmL4TN9Q=
@@ -4,7 +4,7 @@ All notable changes to this project's source code will be documented in this fil
4
4
  Migration instructions for the major updates can be found [here](docs/basics/upgrading-react-on-rails.md#upgrading-to-version-9.md). Some smaller migration information can be found here.
5
5
 
6
6
  ## Need Help Migrating?
7
- If you would like help in migrating between React on Rails versions or help with implementing server rendering, please contact [justin@shakacode.com](mailto:justin@shakacode.com) for information about our [ShakaCode Pro Support](https://www.shakacode.com/work/shakacode-pro-support.pdf).
7
+ If you would like help in migrating between React on Rails versions or help with implementing server rendering, please contact [justin@shakacode.com](mailto:justin@shakacode.com) for information about our [React on Rails Pro Support Options](https://www.shakacode.com/react-on-rails-pro).
8
8
 
9
9
  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.
10
10
 
@@ -15,12 +15,67 @@ Please follow the recommendations outlined at [keepachangelog.com](http://keepac
15
15
  Changes since last non-beta release.
16
16
 
17
17
  *Please add entries here for your pull requests that are not yet released.*
18
- ### [11.3.0] - 2019-04-20
18
+
19
+ ## UPCOMING 12.0 RELEASE
20
+ See [docs/basics/upgrading-react-on-rails.md](./docs/basics/upgrading-react-on-rails.md).
21
+
22
+ ### [12.0.0.pre.beta.2]
23
+ * Changed the precompile task to use the rails/webpacker one by default
24
+
25
+ ### [12.0.0.pre.beta.1]
26
+ * Updated generators to use React hooks
27
+
28
+ ### [12.0.0.pre.beta.0]
29
+ Gem version: 12.0.0.pre.beta.0 and npm version 12.0.0-beta.0 released! Please try this out!
30
+
31
+ #### BREAKING CHANGE
32
+ In order to solve the issues regarding React Hooks compatibility, the number of parameters
33
+ for functions is used to determine if you have a generator function that will get invoked to
34
+ return a React component, or you are registering a functional React component. Alternately, you can
35
+ set JavaScript property `renderFunction` on the function for which you want to return to be
36
+ invoked to return the React component. In that case, you won't need to pass any unused params.
37
+ [PR 1268](https://github.com/shakacode/react_on_rails/pull/1268) by [justin808](https://github.com/justin808)
38
+
39
+ See [docs/basics/upgrading-react-on-rails](./docs/basics/upgrading-react-on-rails.md#upgrading-to-v12)
40
+ for details.
41
+
42
+ * Requires the use of rails/webpacker helpers
43
+ * If the webpacker webpack config files exist, then React on Rails will not override the default
44
+ assets:precompile setup by rails/webpacker. The fix is to remove the JS files inside of config/webpack,
45
+ like config/webpack/production.js.
46
+ * Removed **env_javascript_include_tag** and **env_stylesheet_link_tag** as these are replaced by view helpers
47
+ from rails/webpacker
48
+ * Removal of support for old Rubies and Rails.
49
+ * Removal of config.symlink_non_digested_assets_regex as it's no longer needed with rails/webpacker.
50
+ If any business needs this, we can move the code to a separate gem.
51
+ * Added configuration option `same_bundle_for_client_and_server` with default `false` because
52
+
53
+ 1. Production applications would typically have a server bundle that differs from the client bundle
54
+ 2. This change only affects trying to use HMR with react_on_rails with rails/webpacker.
55
+
56
+ The previous behavior was to always go to the webpack-dev-server for the server bundle if the
57
+ webpack-dev-server was running _and_ the server bundle was found in the `manifest.json`.
58
+
59
+ If you are using the **same bundle for client and server rendering**, then set this configuration option
60
+ to `true`. By [justin808](https://github.com/shakacode/react_on_rails/pull/1240).
61
+
62
+ * Added support to export locales in JSON format. New option added `i18n_output_format` which allows to
63
+ specify locales format either `JSON` or `JS`. **`JSON` format is now the default.**
64
+
65
+ Use this config setting to get the old behavior: config.i18n_output_format = 'js'
66
+
67
+ [PR 1271](https://github.com/shakacode/react_on_rails/pull/1271) by [ashgaliyev](https://github.com/ashgaliyev).
68
+
69
+ #### Improved
70
+ - Added Typescript definitions to the Node package. By [justin808](https://github.com/justin808) and [judahmeek](https://github.com/judahmeek) in [PR 1287](https://github.com/shakacode/react_on_rails/pull/1287).
71
+ - Removed unnecessary restriction to keep the server bundle in the same directory with the client bundles. Rails/webpacker 4 has an advanced cleanup that will remove any files in the directory of other webpack files. Removing this restriction allows the server bundle to be created in a sibling directory. By [justin808](https://github.com/shakacode/react_on_rails/pull/1240).
72
+
73
+ ### [11.3.0] - 2019-05-24
19
74
  #### Added
20
75
  - Added method for retrieving any option from `render_options` [PR 1213](https://github.com/shakacode/react_on_rails/pull/1213)
21
76
  by [ashgaliyev](https://github.com/ashgaliyev).
22
77
 
23
- - html_options can now has option for 'tag' to add dynamically html element. like this: `html_options: { tag: "span" }`.
78
+ - html_options has an option for 'tag' to set the html tag name like this: `html_options: { tag: "span" }`.
24
79
  [PR 1208](https://github.com/shakacode/react_on_rails/pull/1208) by [tahsin352](https://github.com/tahsin352).
25
80
 
26
81
  ### [11.2.2] - 2018-12-24
@@ -39,9 +94,9 @@ by [ashgaliyev](https://github.com/ashgaliyev).
39
94
  #### Changed
40
95
  - Changed the default for:
41
96
  ```rb
42
- config.raise_on_prerender_error = Rails.env.development?
97
+ config.raise_on_prerender_error = Rails.env.development?
43
98
  ```
44
-
99
+
45
100
  Thus, developers will need to fix server rendering errors before continuing.
46
101
  [PR 1145](https://github.com/shakacode/react_on_rails/pull/1145) by [justin808](https://github.com/justin808).
47
102
 
@@ -871,7 +926,11 @@ Best done with Object destructing:
871
926
  ##### Fixed
872
927
  - Fix several generator related issues.
873
928
 
874
- [Unreleased]: https://github.com/shakacode/react_on_rails/compare/11.3.0...master
929
+ [Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.0.0-beta.3...master
930
+ [12.0.0.pre.beta.3]: https://github.com/shakacode/react_on_rails/compare/12.0.0-beta.2...12.0.0-beta.3
931
+ [12.0.0.pre.beta.2]: https://github.com/shakacode/react_on_rails/compare/12.0.0-beta.1...12.0.0-beta.2
932
+ [12.0.0.pre.beta.1]: https://github.com/shakacode/react_on_rails/compare/12.0.0-beta.0...12.0.0-beta.1
933
+ [12.0.0.pre.beta.0]: https://github.com/shakacode/react_on_rails/compare/11.3.0...12.0.0-beta.0
875
934
  [11.3.0]: https://github.com/shakacode/react_on_rails/compare/11.2.2...11.3.0
876
935
  [11.2.2]: https://github.com/shakacode/react_on_rails/compare/11.2.1...11.2.2
877
936
  [11.2.1]: https://github.com/shakacode/react_on_rails/compare/11.1.8...11.2.1
@@ -1,46 +1,9 @@
1
1
  # Tips for Contributors
2
2
 
3
- * See [docs/contributor-info/Releasing](./docs/contributor-info/releasing.md) for instructions on releasing.
3
+ * [docs/contributor-info/Releasing](./docs/contributor-info/releasing.md) for instructions on releasing.
4
+ * [docs/contributor-info/pull-requests](./docs/contributor-info/pull-requests.md)
4
5
  * See other docs in [docs/contributor-info](./docs/contributor-info)
5
6
 
6
- ## Summary
7
-
8
- For non-doc fixes:
9
-
10
- * Provide changelog entry in the [unreleased section of the CHANGELOG.md](https://github.com/shakacode/react_on_rails/blob/master/CHANGELOG.md#unreleased).
11
- * Ensure CI passes and that you added a test that passes with the fix and fails without the fix.
12
- * Squash all commits down to one with a nice commit message *ONLY* once final review is given. Make sure this single commit is rebased on top of master.
13
- * Please address all code review comments.
14
- * Ensure that docs are updated accordingly if a feature is added.
15
-
16
- ## Commit Messages
17
-
18
- From [How to Write a Git Commit Message](http://chris.beams.io/posts/git-commit/)
19
-
20
- #### The seven rules of a great git commit message
21
- > Keep in mind: This has all been said before.
22
-
23
- 1. Separate subject from body with a blank line
24
- 1. Limit the subject line to 50 characters
25
- 1. Capitalize the subject line
26
- 1. Do not end the subject line with a period
27
- 1. Use the imperative mood in the subject line
28
- 1. Wrap the body at 72 characters
29
- 1. Use the body to explain what and why vs. how
30
-
31
-
32
- ## Doc Changes
33
-
34
- When making doc changes, we want the change to work on both the gitbook and the regular github site. The issue is that non-doc files will not go to the gitbook site, so doc references to non doc files must use the github URL.
35
-
36
- ### Links to other docs:
37
- * When making references to doc files, use a relative URL path like:
38
- `[Installation Overview](docs/basics/installation-overview.md)`
39
-
40
- * When making references to source code files, use a full url path like:
41
- `[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)`
42
-
43
-
44
7
  ## To run tests:
45
8
  * After updating code via git, to prepare all examples and run all tests:
46
9
 
@@ -91,52 +54,63 @@ gem "react_on_rails", path: "../path-to-react-on-rails"
91
54
 
92
55
  Note that you will need to bundle install after making this change, but also that **you will need to restart your Rails application if you make any changes to the gem**.
93
56
 
94
- ## Testing the Node package for react-on-rails
57
+ ## Testing the Node package for react-on-rails via Yalc
95
58
  In addition to testing the Ruby parts out, you can also test the node package parts of the gem with an external application. First, be **sure** to build the NPM package:
96
59
 
97
60
  ```sh
98
61
  cd react_on_rails/
99
62
  yarn
100
- yarn run build
101
- yarn install-react-on-rails
63
+
64
+ # Update the lib directory with babel compiled files
65
+ yarn run build:watch
102
66
  ```
67
+
68
+ You need to do this once:
103
69
 
104
- Install the local package by using yarn link, like this:
105
- ```sh
70
+ ```
71
+ # Will send the updates to other folders
72
+ yalc publish
73
+ cd spec/dummy
74
+ yalc add react-on-rails
75
+ ```
76
+
77
+ The workflow is:
78
+ 1. Make changes to the node package.
79
+ 2. We need yalc to push and then run yarn:
80
+ ```
81
+ cd <top dir>
82
+ # Will send the updates to other folders
83
+ yalc push
106
84
  cd spec/dummy
85
+
86
+ # Will update from yalc
107
87
  yarn
108
88
  ```
109
89
 
110
- Note, yarn will run the `postinstall` script of `spec/dummy/client` which runs `yarn link` to set up a sym link to the parent package.
90
+ When you run `yalc push`, you'll get an informative message
111
91
 
112
- #### Example: Testing NPM changes with the dummy app
113
- 1. Add `console.log('Hello!')` [here](https://github.com/shakacode/react_on_rails/blob/master/node_package/src/clientStartup.js#L181) in `react_on_rails/node_package/src/clientStartup.js` to confirm we're getting an update to the node package.
114
- 2. Refresh the browser if the server is already running or start the server using `foreman start` from `react_on_rails/spec/dummy` and navigate to `http://localhost:5000/`. You will now see the `Hello!` message printed in the browser's console.
92
+ ```
93
+ yalc push
94
+ react-on-rails@12.0.0-12070fd1 published in store.
95
+ Pushing react-on-rails@12.0.0 in /Users/justin/shakacode/react-on-rails/react_on_rails/spec/dummy
96
+ Package react-on-rails@12.0.0-12070fd1 added ==> /Users/justin/shakacode/react-on-rails/react_on_rails/spec/dummy/node_modules/react-on-rails.
97
+ Don't forget you may need to run yarn after adding packages with yalc to install/update dependencies/bin scripts.
98
+ ```
115
99
 
116
- _Note: running `npm i` automatically builds the npm package before installing. However, when using yarn you will need to run `yarn run build` in the root directory before the install script. This will be updated when [yarn issue #2649](https://github.com/yarnpkg/yarn/issues/2649) (above) is resolved._
100
+ #### Example: Testing NPM changes with the dummy app
101
+ 1. Add `console.log('Hello!')` to [clientStartup.ts, function render](https://github.com/shakacode/react_on_rails/blob/master/node_package/src/clientStartup.ts in `/node_package/src/clientStartup.js` to confirm we're getting an update to the node package client side. Do the same for function `serverRenderReactComponent` in `/node_package/src/serverRenderReactComponent.ts`.
102
+ 2. Refresh the browser if the server is already running or start the server using `foreman start` from `react_on_rails/spec/dummy` and navigate to `http://localhost:5000/`. You will now see the `Hello!` message printed in the browser's console. If you did not see that message, then review the steps above for the workflow of making changes and pushing them via yalc.
117
103
 
118
104
  # Development Setup for Gem and Node Package Contributors
119
105
 
120
- ## Checklist before Committing
121
- 1. `rake`: runs all linters and specs (you need Docker setup, see below)
122
- 2. Did you need any more tests for your change?
123
- 3. Did you document your change? Update the README.md?
124
-
125
106
  ## Dev Initial Setup
126
107
 
127
108
  ### Prereqs
128
109
  After checking out the repo, making sure you have rvm and nvm setup (setup ruby and node), cd to `spec/dummy` and run `bin/setup` to install ruby dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
129
110
 
130
111
  ### Local Node Package
131
- Because the example and dummy apps rely on the react-on-rails node package, they should link directly to your local version to pick up any changes you may have made to that package. To achieve this, switch to the dummy app's root directory and run this command below which runs something like [this script](spec/dummy/package.json#L14)
132
-
133
- ```sh
134
- cd react_on_rails/spec/dummy
135
- yarn run install-react-on-rails
136
- ```
137
- _Note: this runs npm under the hood as explained in **Test NPM for react-on-rails** section above_
138
112
 
139
- From now on, the example and dummy apps will use your local node_package folder as the react-on-rails node package. This will also be done automatically for you via the `rake examples:gen_all` rake task.
113
+ Note, the example and dummy apps will use your local node_package folder as the react-on-rails node package. This will also be done automatically for you via the `rake examples:gen_all` rake task.
140
114
 
141
115
  *Side note: It's critical to use the alias section of the webpack config to avoid a double inclusion error. This has already been done for you in the example and dummy apps, but for reference:*
142
116
 
@@ -182,13 +156,6 @@ cd react_on_rails/spec/dummy
182
156
  rspec
183
157
  ```
184
158
 
185
- Eventually, we may have JS tests:
186
-
187
- ```sh
188
- cd react_on_rails/spec/dummy/client
189
- yarn run test
190
- ```
191
-
192
159
  ### Run most tests and linting
193
160
 
194
161
  ```sh
@@ -197,7 +164,7 @@ yarn run check
197
164
  ```
198
165
 
199
166
  ### Starting the Dummy App
200
- To run the dummy app, it's **CRITICAL** to not just run `rails s`. You have to run `foreman start`. If you don't do this, then `webpack` will not generate a new bundle, and you will be seriously confused when you change JavaScript and the app does not change. If you change the webpack configs, then you need to restart foreman. If you change the JS code for react-on-rails, you need to run `yarn run build`. Since the react-on-rails package should be sym linked, you don't have to `yarn react-on-rails` after every change.
167
+ To run the dummy app, it's **CRITICAL** to not just run `rails s`. You have to run `foreman start` with one of the Procfiles. If you don't do this, then `webpack` will not generate a new bundle, and you will be seriously confused when you change JavaScript and the app does not change. If you change the webpack configs, then you need to restart foreman. If you change the JS code for react-on-rails, you need to run `yarn run build`. Since the react-on-rails package should be sym linked, you don't have to `yarn react-on-rails` after every change.
201
168
 
202
169
  ### RSpec Testing
203
170
  Run `rake` for testing the gem and `spec/dummy`. Otherwise, the `rspec` command only works for testing within the sample apps, like `spec/dummy`.
@@ -219,10 +186,26 @@ In your Rails app add this gem with a path to your fork.
219
186
 
220
187
  ```ruby
221
188
  gem 'react_on_rails', path: '../relative/path/to/react_on_rails'
222
- ```
189
+ ```
190
+
191
+ Then run `bundle`.
223
192
 
224
193
  The main installer can be run with ```rails generate react_on_rails:install```
225
194
 
195
+ Then use yalc to add the npm module.
196
+
197
+ Be sure that your ran this first at the top level of React on Rails
198
+
199
+ ```
200
+ yalc publish
201
+ ```
202
+
203
+ Then add the node package to your test app:
204
+
205
+ ```
206
+ yalc add react-on-rails
207
+ ```
208
+
226
209
  ### Testing the Generator
227
210
  The generators are covered by generator tests using Rails's generator testing helpers, but it never hurts to do a sanity check and explore the API. See [generator_testing_script.md](generator_testing_script.md) for a script on how to run the generator on a fresh project.
228
211
 
@@ -247,6 +230,12 @@ You can run specific linting for directories or files by using `docker-compose r
247
230
 
248
231
  `docker-compose run lint bash` sets you up to run from the container command line.
249
232
 
233
+ ### Updating Rubocop
234
+ 2 files require updating to update the Rubocop version:
235
+
236
+ 1. `react_on_rails.gemspec`
237
+ 2. `spec/dummy/Gemfile`
238
+
250
239
  ### Docker CI - Test and Linting
251
240
  Docker CI and Tests containers have a xvfd server automatically started for headless browser testing with selenium and Firefox.
252
241
 
data/Gemfile CHANGED
@@ -15,14 +15,14 @@ gem "jbuilder"
15
15
  gem "jquery-rails"
16
16
  gem "mini_racer"
17
17
  gem "puma"
18
-
19
18
  gem "rails_12factor"
20
19
  gem "ruby-lint", require: false
21
20
  gem "sass-rails"
22
21
  gem "scss_lint", require: false
23
22
  gem "sdoc", group: :doc
24
23
  gem "spring"
25
- gem "sqlite3"
24
+ gem "sprockets", "~>3.0"
25
+ gem "sqlite3", "~> 1.3.6"
26
26
  gem "turbolinks"
27
27
  gem "uglifier"
28
28
  gem "web-console", group: :development
@@ -34,8 +34,7 @@ gem "launchy"
34
34
  gem "rspec-rails"
35
35
  gem "rspec-retry"
36
36
  gem "selenium-webdriver"
37
- gem "webdrivers", "~> 3.0"
38
- gem "webpacker"
37
+ gem "webpacker", ">= 4.0.0"
39
38
 
40
39
  gem "equivalent-xml", github: "mbklein/equivalent-xml"
41
40
  gem "rainbow"
@@ -1,6 +1,7 @@
1
+ React on Rails Pro License
1
2
  For React on Rails Pro, not the open source version. For open source, see https://github.com/shakacode/react_on_rails/blob/master/LICENSE.md.
2
3
 
3
- Copyright (c) 2018 Justin Gordon and ShakaCode, http://www.shakacode.com
4
+ Copyright (c) 2018, 2019 Justin Gordon and ShakaCode, http://www.shakacode.com
4
5
 
5
6
  All rights reserved.
6
7
 
@@ -19,7 +20,7 @@ In order to use the Software under this Agreement, you must receive a “Source
19
20
 
20
21
  1.1 General Use. This Agreement grants you a non-exclusive, non-transferable, limited license to the use rights for the Software, without the right to grant sublicenses, subject to the terms and conditions in this Agreement. The Software is licensed, not sold.
21
22
 
22
- 1.2 Unlimited Organization License. If you purchased an Organization License (included with the React on Rails Pro Software), you may install the Software on an unlimited number of Hosts. “Host” means any physical or virtual machine which is controlled by you. You may concurrently run the software on an unlimited number of Hosts, with each host running an unlimited number of Workers.
23
+ 1.2 Unlimited Organization License. You may install the Software on an unlimited number of Hosts. “Host” means any physical or virtual machine which is controlled by you. You may concurrently run the software on an unlimited number of Hosts, with each host running an unlimited number of Workers.
23
24
 
24
25
  1.3 Archive Copies. You are entitled to make a reasonable amount of copies of the Software for archival purposes. Each copy must reproduce all copyright and other proprietary rights notices on or in the Software Product.
25
26
 
@@ -33,15 +34,11 @@ In order to use the Software under this Agreement, you must receive a “Source
33
34
 
34
35
  3.2 UNDER NO CIRCUMSTANCES MAY YOU USE THE SOFTWARE AS PART OF A PRODUCT OR SERVICE THAT PROVIDES SIMILAR FUNCTIONALITY TO THE SOFTWARE ITSELF.
35
36
 
36
- The Open Source version of the Software (“LGPL Version”) is licensed
37
- under the terms of the GNU Lesser General Public License versions 3.0
38
- (“LGPL”) and not under this EULA.
39
-
40
37
  4. Ownership. Notwithstanding anything to the contrary contained herein, except for the limited license rights expressly provided herein, ShakaCode and its suppliers have and will retain all rights, title and interest (including, without limitation, all patent, copyright, trademark, trade secret and other intellectual property rights) in and to the Software and all copies, modifications and derivative works thereof (including any changes which incorporate any of your ideas, feedback or suggestions). You acknowledge that you are obtaining only a limited license right to the Software, and that irrespective of any use of the words “purchase”, “sale” or like terms hereunder no ownership rights are being conveyed to you under this Agreement or otherwise.
41
38
 
42
39
  5. Fees and Payment. The Software license fees will be due and payable in full as set forth in the applicable invoice or at the time of purchase. If the Software does not function properly within two weeks of purchase, please contact us within those two weeks for a refund. You shall be responsible for all taxes, withholdings, duties and levies arising from the order (excluding taxes based on the net income of ShakaCode).
43
40
 
44
- 6. Support, Maintenance and Services. Subject to the terms and conditions of this Agreement, as set forth in your invoice, and as set forth on the React on Rails Pro support page (https://github.com/shakacode/react_on_rails/wiki/Commercial-Support), support and maintenance services may be included with the purchase of your license subscription.
41
+ 6. Support, Maintenance and Services. Subject to the terms and conditions of this Agreement, as set forth in your invoice, and as set forth in the attached Master Service Agreement included with the purchase of your license subscription.
45
42
 
46
43
  7. Term of Agreement.
47
44
 
@@ -52,6 +49,7 @@ under the terms of the GNU Lesser General Public License versions 3.0
52
49
  7.3 Expiration of License. Upon the expiration of any term under this Agreement, (a) all Software updates and services pursuant to the license shall cease, (b) you may only continue to run existing installations of the Software, (c) you may not install the Software on any additional Hosts, and (d) any new installation of the Software shall require the purchase of a new license subscription from ShakaCode.
53
50
 
54
51
  8. Disclaimer of Warranties. The Software is provided "as is," with all faults, defects and errors, and without warranty of any kind. ShakaCode does not warrant that the Software will be free of bugs, errors, viruses or other defects, and ShakaCode shall have no liability of any kind for the use of or inability to use the Software, the Software content or any associated service, and you acknowledge that it is not technically practicable for ShakaCode to do so.
52
+
55
53
  To the maximum extent permitted by applicable law, ShakaCode disclaims all warranties, express, implied, arising by law or otherwise, regarding the Software, the Software content and their respective performance or suitability for your intended use, including without limitation any implied warranty of merchantability, fitness for a particular purpose.
56
54
 
57
55
  9. Limitation of Liability.
@@ -72,12 +70,11 @@ In no event will ShakaCode's liability exceed the Software license price as indi
72
70
 
73
71
  12. Third Party Software. Examples included in Software may provide links to third party libraries or code (collectively “Third Party Software”) to implement various functions. Third Party Software does not comprise part of the Software. In some cases, access to Third Party Software may be included along with the Software delivery as a convenience for demonstration purposes. Such source code and libraries may be included in the “…/examples” source tree delivered with the Software and do not comprise the Software. Licensee acknowledges (1) that some part of Third Party Software may require additional licensing of copyright and patents from the owners of such, and (2) that distribution of any of the Software referencing or including any portion of a Third Party Software may require appropriate licensing from such third parties.
74
72
 
75
-
76
73
  13. Miscellaneous
77
74
 
78
75
  13.1 Entire Agreement. This Agreement sets forth our entire agreement with respect to the Software and the subject matter hereof and supersedes all prior and contemporaneous understandings and agreements whether written or oral.
79
76
 
80
- 13.2 Amendment. ShakaCode reserves the right, in its sole discretion, to amend this Agreement from time. Amendments to this Agreement can be located at: https://github.com/shakacode/react_on_rails/blob/master/COMM-LICENSE.
77
+ 13.2 Amendment. ShakaCode reserves the right, in its sole discretion, to amend this Agreement from time. Amendments to this Agreement can be located at: https://github.com/shakacode/react_on_rails/blob/master/REACT-ON-RAILS-PRO-LICENSE.
81
78
 
82
79
  13.3 Assignment. You may not assign this Agreement or any of its rights under this Agreement without the prior written consent of ShakaCode and any attempted assignment without such consent shall be void.
83
80
 
data/README.md CHANGED
@@ -1,83 +1,75 @@
1
- # ReactOnRails
1
+ ![reactrails](https://user-images.githubusercontent.com/10421828/79436261-52159b80-7fd9-11ea-994e-2a98dd43e540.png)
2
+
3
+ <p align="center">
4
+ <a href="https://shakacode.com/"><img src="https://user-images.githubusercontent.com/10421828/79436256-517d0500-7fd9-11ea-9300-dfbc7c293f26.png"></a>
5
+ <a href="https://forum.shakacode.com/"><img src="https://user-images.githubusercontent.com/10421828/79436266-53df5f00-7fd9-11ea-94b3-b985e1b05bdc.png"></a>
6
+ <a href="https://forum.shakacode.com/t/react-on-rails-pro-2020-shave-the-yak/1842"><img src="https://user-images.githubusercontent.com/10421828/79436265-53df5f00-7fd9-11ea-8220-fc474f6a856c.png"></a>
7
+ <a href="https://github.com/sponsors/shakacode"><img src="https://user-images.githubusercontent.com/10421828/79466109-cdd90d80-8004-11ea-88e5-25f9a9ddcf44.png"></a>
8
+ </p>
9
+
10
+ ---
2
11
 
3
12
  [![License](https://img.shields.io/badge/license-mit-green.svg)](./LICENSE.md) [![Build Status](https://travis-ci.org/shakacode/react_on_rails.svg?branch=master)](https://travis-ci.org/shakacode/react_on_rails) [![Gem Version](https://badge.fury.io/rb/react_on_rails.svg)](https://badge.fury.io/rb/react_on_rails) [![npm version](https://badge.fury.io/js/react-on-rails.svg)](https://badge.fury.io/js/react-on-rails) [![Code Climate](https://codeclimate.com/github/shakacode/react_on_rails/badges/gpa.svg)](https://codeclimate.com/github/shakacode/react_on_rails) [![Coverage Status](https://coveralls.io/repos/shakacode/react_on_rails/badge.svg?branch=master&service=github)](https://coveralls.io/github/shakacode/react_on_rails?branch=master) [![](https://ruby-gem-downloads-badge.herokuapp.com/react_on_rails?type=total)](https://rubygems.org/gems/react_on_rails)
4
13
 
14
+ *These are the docs for React on Rails 12, coming soon. To see the version 11 docs, [click here](https://github.com/shakacode/react_on_rails/tree/11.3.0).*
15
+
16
+ #### News
17
+ **June 24, 2020**:
18
+ 1. Gem version: 12.0.0.pre.beta.3 and npm version 12.0.0-beta.3 released! Please try this out!
19
+ Major enhancements:
20
+ 1. Proper support for React Hooks
21
+ 2. Typescript bindings
22
+ 3. i18n support for generating a JSON file rather than a JS file.
23
+ 4. Tighter rails/webpacker integration
24
+
25
+ Be sure to see the [CHANGELOG.md](./CHANGELOG.md) and read the upgrade instructions:
26
+ [docs/basics/upgrading-react-on-rails](./docs/basics/upgrading-react-on-rails.md#upgrading-to-v12).
27
+
28
+ 2. See Justin's RailsConf talk: [Webpacker, It-Just-Works, But How?](http://railsconf.com/2020/video/justin-gordon-webpacker-it-just-works-but-how).
29
+
30
+ **April 2, 2020**:
31
+ * Are you interested in support for React on Rails? If so check out [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
32
+ * HMR is working with [Loadable Components](https://loadable-components.com) for a both amazing hot-reloading developer experience and great runtime performance. Please [email me](mailto:justin@shakacode.com) if you'd like to use [Loadable Components Code Splitting](https://loadable-components.com/docs/code-splitting/) to speed up your app by reducing your bundle sizes and lazily loading the code that's needed.
33
+ * `react_on_rails` fully supports `rails/webpacker`. The example test app in `spec/dummy` was recently converted over to use rails/webpacker v4. It's a good example of how to leverage rails/webpacker's webpack configuration.
34
+
35
+ ---
36
+
37
+ #### About
5
38
  React on Rails integrates Rails with (server rendering of) Facebook's [React](https://github.com/facebook/react) front-end framework.
6
39
 
7
- Interested in optimizing your webpack setup for React on Rails including code splitting with react-router v4, webpack v4, and react-loadable with server side rendering? [Contact Justin Gordon](mailto:justin@shakacode.com).
40
+ This project is sponsored by the software consulting firm [ShakaCode](https://www.shakacode.com). We focus on React front-ends, often with Ruby on Rails or Gatsby. The best way to see what we do is to see the details of [our recent work](https://www.shakacode.com/recent-work).
41
+
42
+ Interested in optimizing your webpack setup for React on Rails including code splitting with react-router v4, webpack v4, and react-loadable with server side rendering? We just did this for Popmenu, [lowering Heroku costs 20-25% while getting a 73% decrease in average response times](https://www.shakacode.com/recent-work/popmenu/).
43
+
44
+ Feel free to contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com), maintainer of React on Rails, for more information.
45
+
46
+ [Click to join **React + Rails Slack**](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
8
47
 
9
48
  # Intro
10
49
 
11
50
  ## Project Objective
12
51
 
13
- To provide an opinionated and optimal framework for integrating Ruby on Rails with React via the [**Webpacker**](https://github.com/rails/webpacker) gem especially in regards to React Server Rendering.
52
+ To provide a high performance framework for integrating Ruby on Rails with React via the [**Webpacker**](https://github.com/rails/webpacker) gem especially in regards to React Server Rendering.
14
53
 
15
54
  ## Features and Why React on Rails?
16
55
 
17
56
  Given that rails/webpacker gem already provides basic React integration, why would you use "React on Rails"?
18
57
 
19
- 1. Server rendering, often used for SEO crawler indexing and UX performance, is not offered by rails/webpacker.
20
58
  1. The easy passing of props directly from your Rails view to your React components rather than having your Rails view load and then make a separate request to your API.
59
+ 1. Tight integration with [rails/webpacker](https://github.com/rails/webpacker).
60
+ 1. Server rendering, often used for SEO crawler indexing and UX performance, is not offered by rails/webpacker.
21
61
  1. [Redux](https://github.com/reactjs/redux) and [React Router](https://github.com/reactjs/react-router) integration with server-side-rendering.
22
62
  1. [Internationalization (I18n) and (localization)](https://github.com/shakacode/react_on_rails/blob/master/docs/basics/i18n.md)
23
- 1. [RSpec Test Helpers Configuration](docs/basics/rspec-configuration.md) to ensure your Webpack bundles are ready for tests. _(and for [Minitest](docs/basics/minitest-configuration.md))._
24
63
  1. A supportive community. This [web search shows how live public sites are using React on Rails](https://publicwww.com/websites/%22react-on-rails%22++-undeveloped.com/).
25
64
  1. [Reason ML Support](https://github.com/shakacode/reason-react-on-rails-example).
26
65
 
27
-
28
66
  See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
29
67
 
30
68
  ## ShakaCode Forum Premium Content
31
- _Requires creating a free account._
69
+ _Requires creating a free account._
70
+
32
71
  * [How to use different versions of a file for client and server rendering](https://forum.shakacode.com/t/how-to-use-different-versions-of-a-file-for-client-and-server-rendering/1352)
33
72
 
34
- ## React on Rails Pro and ShakaCode Pro Support
35
-
36
- React on Rails Pro provides Node server rendering and other performance enhancements for React on Rails.
37
-
38
- [![2018-09-11_10-31-11](https://user-images.githubusercontent.com/1118459/45467845-5bcc7400-b6bd-11e8-91e1-e0cf806d4ea4.png)](https://blog.shakacode.com/hvmns-90-reduction-in-server-response-time-from-react-on-rails-pro-eb08226687db)
39
-
40
- * [HVMN Testimonial, by Paul Benigeri, October 12, 2018](./docs/testimonials/hvmn.md)
41
- * [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)
42
- * [Egghead React on Rails Pro Deployment Highlights](https://github.com/shakacode/react_on_rails/wiki/Egghead-React-on-Rails-Pro-Deployment-Highlights)
43
-
44
- For more information, see the [React on Rails Pro Docs](https://github.com/shakacode/react_on_rails/wiki).
45
-
46
- The [ShakaCode Pro Support Plan](http://www.shakacode.com/work/shakacode-pro-support.pdf) can help you with:
47
-
48
- * Optimizing your webpack setup to Webpack v4 for React on Rails including code splitting with react-router v4, webpack v4, and react-loadable.
49
- * Upgrading your app to use the current Webpack setup that skips the Sprockets asset pipeline.
50
- * Better performance client and server side.
51
- * Efficiently migrating from [Angular to React](https://www.shakacode.com/services/angular-to-react/).
52
- * Best practices based on over four years of React on Rails experience.
53
- * Using [Reason](https://reasonml.github.io/) with (or without) React on Rails.
54
-
55
- ShakaCode can also help you with your custom software development needs. We specialize in marketplace and e-commerce applications that utilize both Rails and React. Because we own [HawaiiChee.com](https://www.hawaiichee.com), we can leverage that code for your app!
56
-
57
- The article [Why Hire ShakaCode?](https://blog.shakacode.com/can-shakacode-help-you-4a5b1e5a8a63#.jex6tg9w9) provides additional details about our projects.
58
-
59
- Please [email me (Justin Gordon), the creator of React on Rails](mailto:justin@shakacode.com), to see if I can help you or if you want an invite to our private Slack room for ShakaCode.
60
-
61
- ## Testimonials for Hiring ShakaCode and our "Pro Support"
62
-
63
- [HVMN Testimonial, Written by Paul Benigeri, October 12, 2018](./docs/testimonials/hvmn.md)
64
-
65
- > 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.
66
-
67
- [ResortPass Testimonial, by Leora Juster, December 10, 2018](./docs/testimonials/resortpass.md)
68
-
69
- > 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.
70
-
71
- From Kyle Maune of Cooper Aerial, May 4, 2018
72
-
73
- ![image](https://user-images.githubusercontent.com/1118459/40891236-9b0b406e-671d-11e8-80ee-c026dbd1d5a2.png)
74
-
75
- From Joel Hooks, Co-Founder, Chief Nerd at [egghead.io](https://egghead.io/), January 30, 2017:
76
-
77
- ![2017-01-30_11-33-59](https://cloud.githubusercontent.com/assets/1118459/22443635/b3549fb4-e6e3-11e6-8ea2-6f589dc93ed3.png)
78
-
79
- For more testimonials, see [Live Projects](PROJECTS.md) and [Kudos](./KUDOS.md).
80
-
81
73
  ----
82
74
 
83
75
  # Docs
@@ -86,7 +78,7 @@ For more testimonials, see [Live Projects](PROJECTS.md) and [Kudos](./KUDOS.md).
86
78
 
87
79
  ## Prerequisites
88
80
 
89
- React on Rails supports older versions of Rails back to 3.x. Rails/webpacker requires version 4.2+.
81
+ Ruby on Rails >=5 and rails/webpacker 4.2+.
90
82
 
91
83
  ## Getting Started
92
84
 
@@ -101,23 +93,10 @@ Note, the best way to understand how to use ReactOnRails is to study a few simpl
101
93
 
102
94
  *See also [the instructions for installing into an existing Rails app](docs/basics/installation-into-an-existing-rails-app.md).*
103
95
 
104
- 1. Create a new Rails app:
105
-
106
- ``````bash
107
- $ rails new my-app --webpack=react
108
- $ cd my-app
109
- ``````
110
-
111
96
  2. Add the `react_on_rails` gem to Gemfile:
112
97
 
113
- ```ruby
114
- gem 'react_on_rails', '11.1.4' # Use the exact gem version to match npm version
115
- ```
116
-
117
- 3. Install the `react_on_rails` gem:
118
-
119
98
  ```bash
120
- $ bundle install
99
+ bundle add react_on_rails --strict
121
100
  ```
122
101
 
123
102
  4. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`).
@@ -125,13 +104,13 @@ Note, the best way to understand how to use ReactOnRails is to study a few simpl
125
104
  5. Run the generator:
126
105
 
127
106
  ```bash
128
- $ rails generate react_on_rails:install
107
+ rails generate react_on_rails:install
129
108
  ```
130
109
 
131
110
  6. Start the app:
132
111
 
133
112
  ```bash
134
- $ rails s
113
+ rails s
135
114
  ```
136
115
 
137
116
  7. Visit http://localhost:3000/hello_world.
@@ -150,13 +129,18 @@ Below is the line where you turn server rendering on by setting `prerender` to t
150
129
  <%= react_component("HelloWorld", props: @hello_world_props, prerender: false) %>
151
130
  ```
152
131
 
132
+ Note, if you got an error in your console regarding "ReferenceError: window is not defined",
133
+ then you need to edit `config/webpacker.yml` and set `hmr: false` and `inline: false`.
134
+ See [rails/webpacker PR 2644](https://github.com/rails/webpacker/pull/2644) for a fix for this
135
+ issue.
136
+
153
137
  ## Basic Usage
154
138
 
155
139
  ### Configuration
156
140
 
157
141
  * Configure `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [docs/basics/configuration.md](docs/basics/configuration.md) for documentation of all configuration options.
158
- * Configure `config/webpacker.yml`. If you used the generator and the default webpacker setup, you don't need to touch this file. If you are customizing your setup, then consult the [spec/dummy/config/webpacker.yml](./spec/dummy/config/webpacker.yml) example
159
- * Set `compile: false` for all envs
142
+ * Configure `config/webpacker.yml`. If you used the generator and the default webpacker setup, you don't need to touch this file. If you are customizing your setup, then consult the [spec/dummy/config/webpacker.yml](./spec/dummy/config/webpacker.yml) example or the official default [webpacker.yml](https://github.com/rails/webpacker/blob/master/lib/install/config/webpacker.yml).
143
+ * Tip: set `compile: false` for development if you know that you'll always be compiling with a watch process. Otherwise, every request will check if compilation is needed.
160
144
  * Your `public_output_path` must match your Webpack configuration for `output` of your bundles.
161
145
  * Only set `cache_manifest` to `true` in your production env.
162
146
 
@@ -191,13 +175,14 @@ Below is the line where you turn server rendering on by setting `prerender` to t
191
175
  <%= react_component("HelloWorld", props: { name: "Stranger" }) %>
192
176
  ```
193
177
 
194
- - This is what your HelloWorld.js file might contain. The railsContext is always available for any parameters that you _always_ want available for your React components. It has _nothing_ to do with the concept of the [React Context](https://reactjs.org/docs/context.html). See [Generator Functions and the RailsContext](docs/basics/generator-functions-and-railscontext.md) for more details on this topic.
178
+ - This is what your HelloWorld.js file might contain. The railsContext is always available for any parameters that you _always_ want available for your React components. It has _nothing_ to do with the concept of the [React Context](https://reactjs.org/docs/context.html). See [render functions and the RailsContext](docs/basics/render-functions-and-railscontext.md) for more details on this topic.
195
179
 
196
180
  ```js
197
181
  import React from 'react';
198
182
 
199
183
  export default (props, railsContext) => {
200
- return (
184
+ // Note wrap in a function to make this a React function component
185
+ return () => (
201
186
  <div>
202
187
  Your locale is {railsContext.i18nLocale}.<br/>
203
188
  Hello, {props.name}!
@@ -210,7 +195,7 @@ See the [View Helpers API](./docs/api/view-helpers-api.md) for more details on `
210
195
 
211
196
  ## Fragment Caching
212
197
 
213
- Fragment caching is a [React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki) feature. Fragment caching is a **HUGE** performance booster for your apps. Use the `cached_react_component` and `cached_react_component_hash`. The API is the same as `react_component` and `react_component_hash`, but for 2 differences:
198
+ Fragment caching is a [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro) feature. Fragment caching is a **HUGE** performance booster for your apps. Use the `cached_react_component` and `cached_react_component_hash`. The API is the same as `react_component` and `react_component_hash`, but for 2 differences:
214
199
 
215
200
  1. The `cache_key` takes the same parameters as any Rails `cache` view helper.
216
201
  1. The **props** are passed via a block so that evaluation of the props is not done unless the cache is broken. Suppose you put your props calculation into some method called `some_slow_method_that_returns_props`:
@@ -232,7 +217,7 @@ Note, even without server rendering (without step 3 above), fragment caching is
232
217
 
233
218
  ## Integration with Node.js for Server Rendering
234
219
 
235
- Default server rendering is done by ExecJS. If you want to use a Node.js server for better performing server rendering, [email justin@shakacode.com](mailto:justin@shakacode.com). ShakaCode has built a premium Node rendering server that is part of [React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki).
220
+ Default server rendering is done by ExecJS. If you want to use a Node.js server for better performing server rendering, [email justin@shakacode.com](mailto:justin@shakacode.com). ShakaCode has built a premium Node rendering server that is part of [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
236
221
 
237
222
  ## Globally Exposing Your React Components
238
223
 
@@ -257,21 +242,39 @@ Another way is to use a separate webpack configuration file that can use a diffe
257
242
 
258
243
  For details on techniques to use different code for client and server rendering, see: [How to use different versions of a file for client and server rendering](https://forum.shakacode.com/t/how-to-use-different-versions-of-a-file-for-client-and-server-rendering/1352). (_Requires creating a free account._)
259
244
 
260
- ## Specifying Your React Components: Direct or Generator Functions
245
+ ## Specifying Your React Components: Register directly or use render-functions
261
246
 
262
- You have two ways to specify your React components. You can either register the React component directly, or you can create a function that returns a React component. Creating a function has the following benefits:
247
+ You have two ways to specify your React components. You can either register the React component (either function or class component) directly, or you can create a function that returns a React component, which we using the name of a "render-function". Creating a render-function allows:
263
248
 
264
- 1. You have access to the `railsContext`. See documentation for the railsContext in terms of why you might need it. You **need** a generator function to access the `railsContext`.
249
+ 1. You have access to the `railsContext`. See documentation for the railsContext in terms of why you might need it. You **need** a render function to access the `railsContext`.
265
250
  2. You can use the passed-in props to initialize a redux store or set up react-router.
266
251
  3. You can return different components depending on what's in the props.
267
252
 
268
- ReactOnRails will automatically detect a registered generator function. Thus, there is no difference between registering a React Component versus a "generator function."
253
+ Note, the return value of a **render function** should be either a React Function or Class Component, or an object representing server rendering results.
254
+
255
+ Do not return a React Element (JSX).
256
+
257
+ ReactOnRails will automatically detect a registered render function by the fact that the function takes
258
+ more than 1 parameter. In other words, if you want the ability to provide a function that returns the
259
+ React component, then you need to specify at least a second parameter. This is the `railsContext`.
260
+ If you're not using this parameter, declare your function with the unused param:
261
+
262
+ ```js
263
+ const MyComponentGenerator = (props, _railsContext) => {
264
+ if (props.print) {
265
+ // This is a React FunctionComponent because it is wrapped in a function.
266
+ return () => <H1>{JSON.stringify(props)}</H1>;
267
+ }
268
+ }
269
+ ```
270
+
271
+ Thus, there is no difference between registering a React function or class Component versus a "render function."
269
272
 
270
- ## react_component_hash for Generator Functions
273
+ ## react_component_hash for render functions
271
274
 
272
- Another reason to use a generator function is that sometimes in server rendering, specifically with React Router, you need to return the result of calling ReactDOMServer.renderToString(element). You can do this by returning an object with the following shape: { renderedHtml, redirectLocation, error }. Make sure you use this function with `react_component_hash`.
275
+ Another reason to use a render function is that sometimes in server rendering, specifically with React Router, you need to return the result of calling ReactDOMServer.renderToString(element). You can do this by returning an object with the following shape: { renderedHtml, redirectLocation, error }. Make sure you use this function with `react_component_hash`.
273
276
 
274
- For server rendering, if you wish to return multiple HTML strings from a generator function, you may return an Object from your generator function with a single top-level property of `renderedHtml`. Inside this Object, place a key called `componentHtml`, along with any other needed keys. An example scenario of this is when you are using side effects libraries like [React Helmet](https://github.com/nfl/react-helmet). Your Ruby code will get this Object as a Hash containing keys componentHtml and any other custom keys that you added:
277
+ For server rendering, if you wish to return multiple HTML strings from a render function, you may return an Object from your render function with a single top-level property of `renderedHtml`. Inside this Object, place a key called `componentHtml`, along with any other needed keys. An example scenario of this is when you are using side effects libraries like [React Helmet](https://github.com/nfl/react-helmet). Your Ruby code will get this Object as a Hash containing keys componentHtml and any other custom keys that you added:
275
278
 
276
279
  ```js
277
280
  { renderedHtml: { componentHtml, customKey1, customKey2} }
@@ -286,7 +289,8 @@ For details on using react_component_hash with react-helmet, see the docs below
286
289
 
287
290
  ## I18n
288
291
 
289
- You can enable the i18n functionality with [react-intl](https://github.com/yahoo/react-intl). React on Rails provides an option for automatic conversions of Rails `*.yml` locale files into `*.js` files for `react-intl`. See the [How to add I18n](docs/basics/i18n.md) for a summary of adding I18n.
292
+ React on Rails provides an option for automatic conversions of Rails `*.yml` locale files into `*.json` or `*.js*.
293
+ See the [How to add I18n](docs/basics/i18n.md) for a summary of adding I18n.
290
294
 
291
295
  ## More Details
292
296
 
@@ -294,18 +298,16 @@ Browse the links in the [Summary Table of Contents](./SUMMARY.md)
294
298
 
295
299
  Here are some highly recommended next articles to read:
296
300
 
297
- 1. [How React on Rails Works](./docs/basics/how-react-on-rails-works.md)
301
+ 1. [How React on Rails Works](docs/outdated/how-react-on-rails-works.md)
298
302
  1. [Recommended Project Structure](./docs/basics/recommended-project-structure.md)
299
303
  1. [Webpack Configuration](./docs/basics/webpack-configuration.md)
300
304
  1. [View Helpers API](./docs/api/view-helpers-api.md)
301
- 1. [Caching and Performance: React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki).
305
+ 1. [Caching and Performance: React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
302
306
  1. [Deployment](docs/basics/deployment.md).
303
307
 
304
308
  # Support
305
309
 
306
- ## ShakaCode Support
307
-
308
- Aloha, I'm Justin Gordon the creator and maintainer of React on Rails. I'm supporting my continued dedication to this project by project by offering a React on Rails **Pro Support Plan**. Please [email me](mailto:justin@shakacode.com) to see if I can help you.
310
+ [Click to join **React + Rails Slack**](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
309
311
 
310
312
  ## Community Resources
311
313
 
@@ -324,23 +326,58 @@ Please [**click to subscribe**](https://app.mailerlite.com/webforms/landing/l1d9
324
326
 
325
327
  Bug reports and pull requests are welcome. See [Contributing](CONTRIBUTING.md) to get started, and the [list of help wanted issues](https://github.com/shakacode/react_on_rails/labels/contributions%3A%20up%20for%20grabs%21).
326
328
 
329
+ ## React on Rails Pro
330
+
331
+ React on Rails Pro provides Node server rendering, fragment caching, code-splitting, and other performance enhancements for React on Rails. For a case study, see the 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). The [Wiki](https://github.com/shakacode/react_on_rails/wiki) contains more details.
332
+
333
+ [![2018-09-11_10-31-11](https://user-images.githubusercontent.com/1118459/45467845-5bcc7400-b6bd-11e8-91e1-e0cf806d4ea4.png)](https://blog.shakacode.com/hvmns-90-reduction-in-server-response-time-from-react-on-rails-pro-eb08226687db)
334
+
335
+ ## React on Rails Pro Support
336
+
337
+ The [React on Rails Pro Support Plan](https://www.shakacode.com/react-on-rails-pro) can help!
338
+
339
+ * Optimizing your webpack setup to Webpack v4 for React on Rails including code splitting with react-router v4, webpack v4, and react-loadable.
340
+ * Upgrading your app to use the current Webpack setup that skips the Sprockets asset pipeline.
341
+ * Better performance client and server side.
342
+ * Best practices based on over four years of React on Rails experience.
343
+ * Using [Reason](https://reasonml.github.io/) with (or without) React on Rails.
344
+
345
+ ShakaCode can also help you with your custom software development needs. We specialize in marketplace and e-commerce applications that utilize both Rails and React. Because we own [HawaiiChee.com](https://www.hawaiichee.com), we can leverage that code for your app!
346
+
347
+ Please email Justin Gordon [justin@shakacode.com](mailto:justin@shakacode.com), the maintainer of React on Rails, for more information.
348
+
349
+ ## Testimonials for ShakaCode
350
+ [HVMN Testimonial, by Paul Benigeri, October 12, 2018](./docs/testimonials/hvmn.md)
351
+ > 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.
352
+
353
+ [ResortPass Testimonial, by Leora Juster, December 10, 2018](./docs/testimonials/resortpass.md)
354
+
355
+ > 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.
356
+
357
+ From Joel Hooks, Co-Founder, Chief Nerd at [egghead.io](https://egghead.io/), January 30, 2017:
358
+
359
+ ![2017-01-30_11-33-59](https://cloud.githubusercontent.com/assets/1118459/22443635/b3549fb4-e6e3-11e6-8ea2-6f589dc93ed3.png)
360
+
361
+ For more testimonials, see [Live Projects](PROJECTS.md) and [Kudos](./KUDOS.md).
362
+
327
363
  # Supporters
328
364
 
329
365
  The following companies support this open source project, and ShakaCode uses their products! Justin writes React on Rails on [RubyMine](https://www.jetbrains.com/ruby/). We use [Scout](https://scoutapp.com/) to monitor the live performance of [HawaiiChee.com](https://www.hawaiichee.com), [BrowserStack](https://www.browserstack.com) to solve problems with oddball browsers, and [CodersRank](https://codersrank.io/) to find candidates for our team.
330
366
 
367
+ [![2019-09-24_17-48-00](https://user-images.githubusercontent.com/1118459/65567887-96353780-def3-11e9-926d-4a55e2e186ff.png)](https://www.jetbrains.com/ruby/)
331
368
  [![Scout](https://user-images.githubusercontent.com/1118459/41828269-106b40f8-77d0-11e8-8d19-9c4b167ef9d8.png)](https://scoutapp.com/)
332
369
  [![BrowserStack](https://cloud.githubusercontent.com/assets/1118459/23203304/1261e468-f886-11e6-819e-93b1a3f17da4.png)](https://www.browserstack.com)
333
370
  [![CodersRank](https://user-images.githubusercontent.com/1118459/55040254-ad8a7b00-4fcb-11e9-8936-c6765eb30698.png)](https://codersrank.io/?utm_source=github&utm_medium=banner&utm_campaign=shakacode)
334
371
 
335
372
  ## Clubhouse
336
- I've just moved ShakaCode's development to [ClubHouse](https://clubhouse.io/) from Trello. We're going to be doing this with all our projects. If you want to **try ClubHouse and get 2 months free beyond the 14-day trial period**, click [here to use ShakaCode's referral code](http://r.clbh.se/mvfd30S). We're participating in their awesome triple-sided referral program, which you can read about [here](https://clubhouse.io/blog/clubhouse-referral-program-5f614bb437c3). By using our [referral code](http://r.clbh.se/mvfd30S) you'll be supporting ShakaCode and, thus, React on Rails!
373
+ I've just moved ShakaCode's development to [ClubHouse](https://clubhouse.io/) from Trello. We're going to be doing this with all our projects. If you want to **try ClubHouse and get 2 months free beyond the 14-day trial period**, click [here to use ShakaCode's referral code](http://r.clbh.se/mvfoNeH). We're participating in their awesome triple-sided referral program, which you can read about [here](https://clubhouse.io/blog/clubhouse-referral-program-5f614bb437c3). By using our [referral code](http://r.clbh.se/mvfoNeH) you'll be supporting ShakaCode and, thus, React on Rails!
337
374
 
338
375
  *If you'd like to support React on Rails and have your company listed here, [get in touch](mailto:justin@shakacode.com).*
339
376
 
340
377
  Aloha and best wishes from Justin and the ShakaCode team!
341
378
 
342
379
  # Work with Us
343
- ShakaCode is **[currently looking to hire](http://www.shakacode.com/about/#work-with-us)** like-minded, remote-first, developers that wish to work on our projects, including [Hawaii Chee](https://www.hawaiichee.com). Your main coding interview will be pairing with us on our open source! We're getting into [Reason](https://reasonml.github.io/)!
380
+ ShakaCode is **[currently looking to hire](http://www.shakacode.com/about/#work-with-us)** like-minded, remote-first, developers that wish to work on our projects, including [Hawaii Chee](https://www.hawaiichee.com). Your main coding interview will be pairing with us on our open source! We're also using [ReasonML](https://reasonml.github.io/) extensively!
344
381
 
345
382
  # License
346
383