react_on_rails 12.4.0 → 12.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +2 -1
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +23 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  5. data/.github/workflows/main.yml +3 -3
  6. data/.gitignore +0 -3
  7. data/.prettierignore +2 -0
  8. data/CHANGELOG.md +32 -2
  9. data/Gemfile.development_dependencies +7 -6
  10. data/REACT-ON-RAILS-PRO-LICENSE +1 -1
  11. data/README.md +22 -12
  12. data/SUMMARY.md +9 -0
  13. data/docs/deployment/heroku-deployment.md +16 -5
  14. data/docs/guides/configuration.md +26 -12
  15. data/docs/guides/how-react-on-rails-works.md +0 -1
  16. data/docs/guides/tutorial.md +18 -14
  17. data/lib/generators/react_on_rails/base_generator.rb +46 -3
  18. data/lib/generators/react_on_rails/generator_helper.rb +4 -0
  19. data/lib/generators/react_on_rails/templates/.eslintrc +3 -1
  20. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +4 -8
  21. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static +9 -0
  22. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +2 -1
  23. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +4 -0
  24. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorldServer.js +5 -0
  25. data/lib/generators/react_on_rails/templates/base/base/app/javascript/packs/server-bundle.js +8 -0
  26. data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb +1 -0
  27. data/lib/generators/react_on_rails/templates/base/base/babel.config.js.tt +15 -0
  28. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +1 -1
  29. data/lib/generators/react_on_rails/templates/base/base/config/webpack/clientWebpackConfig.js.tt +17 -0
  30. data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +15 -0
  31. data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +27 -0
  32. data/lib/generators/react_on_rails/templates/base/base/config/webpack/production.js.tt +11 -0
  33. data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt +117 -0
  34. data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpackConfig.js.tt +36 -0
  35. data/lib/generators/react_on_rails/templates/base/base/config/webpacker.yml +62 -0
  36. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +2 -1
  37. data/lib/react_on_rails/configuration.rb +70 -35
  38. data/lib/react_on_rails/helper.rb +1 -1
  39. data/lib/react_on_rails/react_component/render_options.rb +14 -0
  40. data/lib/react_on_rails/server_rendering_js_code.rb +13 -0
  41. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +3 -1
  42. data/lib/react_on_rails/version.rb +1 -1
  43. data/lib/tasks/assets.rake +5 -47
  44. data/lib/tasks/locale.rake +1 -2
  45. data/package.json +1 -1
  46. data/rakelib/example_type.rb +5 -1
  47. data/rakelib/examples.rake +8 -3
  48. data/rakelib/release.rake +7 -1
  49. data/rakelib/task_helpers.rb +7 -0
  50. data/react_on_rails.gemspec +3 -3
  51. data/yarn.lock +117 -71
  52. metadata +22 -9
  53. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ab995812150b12121f864f9826f1467bc4fa557b7b63a50a253d222558cce33
4
- data.tar.gz: 3b58277fba79aa38cec6b99782146758cfa5a294f571ed64630b0275ca8e512b
3
+ metadata.gz: 5490e90d68dc9b21393bc6640239432d50872526c092fb88d47aa2c70625bf53
4
+ data.tar.gz: aa540a9735ca1f6e4ffc1609591ffd2882c73102775f335ee4465cecda4c113b
5
5
  SHA512:
6
- metadata.gz: d4abb58e8412368943531aa9ce0c875d5332714b86877a85b0a7ddbf9cf85233df9fe91e6014929041ddf0bc25a0c40e58e0a51082838f9ef2e409aebf552e73
7
- data.tar.gz: 4da65a8f4d3b55b5d0f68e4a639e3e931f5c3babd96012cac4b1822d9416fdecb2e0f32830f5ca6e1910770c3c450ce5549fa3715e07ecec8ddbe00476d85718
6
+ metadata.gz: 9b1bb61ac6ce06aebb68769082403c20665ec89f27672e21a3a40d3f92fa11db7305b24470861f9028985e79c88fb43f4be76684f14eb02928e723030bf7ae23
7
+ data.tar.gz: 45e79902586891bab920ab9e0588bc970bd4f72fd502bad16db63d3194b3650e66119bd0b4dd8892fb3884a8dec9d9d055229954eae9081e6f4d9b20b0d5519d
data/.circleci/config.yml CHANGED
@@ -55,7 +55,7 @@ aliases:
55
55
  command: |
56
56
  gem install bundler
57
57
  echo "Bundler version: "; bundle --version
58
- cd spec/dummy && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
58
+ cd spec/dummy && bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
59
59
 
60
60
  # Install ruby gems unless existing set of gems is satisfying bundler.
61
61
  - &install-package-ruby-gems
@@ -63,6 +63,7 @@ aliases:
63
63
  command: |
64
64
  gem install bundler
65
65
  echo "Bundler version: "; bundle --version
66
+ bundle lock --add-platform 'x86_64-linux'
66
67
  bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
67
68
 
68
69
  # Restore node_modules dir from cache using yarn.lock checksum as a key.
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ A bug is a crash or incorrect behavior. If you have a debugging or troubleshooting question, please open [a discussion](https://github.com/shakacode/react_on_rails/discussions).
11
+
12
+ ## Environment
13
+
14
+ 1. Ruby version:
15
+ 2. Rails version:
16
+ 3. Webpacker version:
17
+ 4. React on Rails version:
18
+
19
+ ## Expected behavior
20
+
21
+ ## Actual behavior
22
+
23
+ ## Small, reproducible repo
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
@@ -55,7 +55,7 @@ jobs:
55
55
  path: spec/dummy/vendor/bundle
56
56
  key: v4-dummy-app-gem-cache-${{ hashFiles('spec/dummy/Gemfile.lock') }}
57
57
  - name: Install Ruby Gems for dummy app
58
- run: cd spec/dummy && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
58
+ run: cd spec/dummy && bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
59
59
  - name: Build test bundles for dummy app
60
60
  run: cd spec/dummy && yarn run build:test
61
61
  - id: get-sha
@@ -131,9 +131,9 @@ jobs:
131
131
  - name: yalc add react-on-rails
132
132
  run: cd spec/dummy && yalc add react-on-rails
133
133
  - name: Install Ruby Gems for package
134
- run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
134
+ run: bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
135
135
  - name: Install Ruby Gems for dummy app
136
- run: cd spec/dummy && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
136
+ run: cd spec/dummy && bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
137
137
  - name: Ensure minimum required Chrome version
138
138
  run: |
139
139
  echo -e "Already installed $(google-chrome --version)\n"
data/.gitignore CHANGED
@@ -11,9 +11,6 @@
11
11
  /vendor/
12
12
 
13
13
  /spec/examples.txt
14
- /spec/dummy/client/node_modules
15
- /spec/dummy/public/webpack/
16
- /spec/dummy/coverage/
17
14
  /spec/react_on_rails/dummy-for-generators/
18
15
 
19
16
  # RVM
data/.prettierignore CHANGED
@@ -8,3 +8,5 @@ gen-examples/examples/*
8
8
  node_package/lib/*
9
9
  spec/react_on_rails/dummy-for-generators/app/javascript/bundles/HelloWorld/*
10
10
  bundle/
11
+ spec/dummy/lib/bs/**
12
+ *.bs.js
data/CHANGELOG.md CHANGED
@@ -17,6 +17,31 @@ Changes since last non-beta release.
17
17
 
18
18
  *Please add entries here for your pull requests that are not yet released.*
19
19
 
20
+ ### [12.6.0] - 2022-01-22
21
+
22
+ ### Added
23
+ - A `rendering_props_extension` configuration which takes a module with an `adjust_props_for_client_side_hydration` method, which is used to process props differently for server/client if `prerender` is set to `true`. [PR 1413](https://github.com/shakacode/react_on_rails/pull/1413) by [gscarv13](https://github.com/gscarv13) & [judahmeek](https://github.com/judahmeek).
24
+
25
+ ### [12.5.2] - 2021-12-29
26
+ ### Fixed
27
+ - Usage of config.build_production_command for custom command for production builds fixed. [PR 1415](https://github.com/shakacode/react_on_rails/pull/1415) by [judahmeek](https://github.com/judahmeek).
28
+
29
+ ### [12.5.1] - 2021-12-27
30
+
31
+ ### Fixed
32
+ - A fatal server rendering error if running an ReactOnRails >=12.4.0 with ReactOnRails Pro <2.4.0. [PR 1412](https://github.com/shakacode/react_on_rails/pull/1412) by [judahmeek](https://github.com/judahmeek).
33
+
34
+ ### [12.5.0] - 2021-12-26
35
+
36
+ #### Added
37
+ - Support for React 18, including the changed SSR API. [PR 1409](https://github.com/shakacode/react_on_rails/pull/1409) by [kylemellander](https://github.com/kylemellander).
38
+ - Added webpack configuration files as part of the generator and updated webpacker to version 6. [PR 1404](https://github.com/shakacode/react_on_rails/pull/1404) by [gscarv13](https://github.com/gscarv13).
39
+ - Supports Rails 7.
40
+
41
+ #### Changed
42
+ - Changed logic of determining the usage of the default rails/webpacker webpack config or a custom command to only check if the config.build_production_command is defined. [PR 1402](https://github.com/shakacode/react_on_rails/pull/1402)by [justin808](https://github.com/justin808) and [gscarv13](https://github.com/gscarv13).
43
+ - Minimimum required Ruby is 2.7 to match lastest rails/webpacker.
44
+
20
45
  ### [12.4.0] - 2021-09-22
21
46
  #### Added
22
47
  - ScoutAPM tracing support for server rendering [PR 1379](https://github.com/shakacode/react_on_rails/pull/1379) by [justin808](https://github.com/justin808).
@@ -82,7 +107,7 @@ invoked to return the React component. In that case, you won't need to pass any
82
107
  [PR 1268](https://github.com/shakacode/react_on_rails/pull/1268) by [justin808](https://github.com/justin808)
83
108
 
84
109
  See [docs/guides/upgrading-react-on-rails](https://www.shakacode.com/react-on-rails/docs/guides/upgrading-react-on-rails#upgrading-to-v12)
85
- for details.
110
+ for details.
86
111
 
87
112
  #### Other Updates
88
113
  * `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 for server-side rendering.
@@ -974,7 +999,12 @@ Best done with Object destructing:
974
999
  ##### Fixed
975
1000
  - Fix several generator related issues.
976
1001
 
977
- [Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.3.0...master
1002
+ [Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.6.0...master
1003
+ [12.6.0]: https://github.com/shakacode/react_on_rails/compare/12.5.2...12.6.0
1004
+ [12.5.2]: https://github.com/shakacode/react_on_rails/compare/12.5.1...12.5.2
1005
+ [12.5.1]: https://github.com/shakacode/react_on_rails/compare/12.5.0...12.5.1
1006
+ [12.5.0]: https://github.com/shakacode/react_on_rails/compare/12.4.0...12.5.0
1007
+ [12.4.0]: https://github.com/shakacode/react_on_rails/compare/12.3.0...12.4.0
978
1008
  [12.3.0]: https://github.com/shakacode/react_on_rails/compare/12.2.0...12.3.0
979
1009
  [12.2.0]: https://github.com/shakacode/react_on_rails/compare/12.1.0...12.2.0
980
1010
  [12.1.0]: https://github.com/shakacode/react_on_rails/compare/12.0.4...12.1.0
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- gem "webpacker"
3
+ gem "webpacker", "6.0.0.rc.6"
4
4
  gem "bootsnap", require: false
5
- gem "rails"
5
+ gem "rails", "~> 7.0"
6
6
  gem "sqlite3"
7
- gem "sass-rails"
7
+ gem "sass-rails", "~> 6.0"
8
8
  gem "uglifier"
9
9
  gem "jquery-rails"
10
10
  gem "puma"
@@ -17,10 +17,11 @@ gem "jbuilder"
17
17
  # bundle exec rake doc:rails generates the API under doc/api.
18
18
  gem "sdoc", group: :doc
19
19
 
20
- gem "sprockets"
20
+ gem "sprockets", "~> 4.0"
21
21
 
22
22
  gem "amazing_print"
23
- gem "mini_racer"
23
+
24
+ gem "mini_racer", "~> 0.5"
24
25
 
25
26
  group :development, :test do
26
27
  gem "listen"
@@ -33,7 +34,7 @@ group :development, :test do
33
34
  gem "rubocop-performance", require: false
34
35
  gem "rubocop-rspec", require: false
35
36
  gem "scss_lint", require: false
36
- gem "spring"
37
+ gem "spring", "~> 4.0"
37
38
  end
38
39
 
39
40
  group :test do
@@ -82,7 +82,7 @@ In no event will ShakaCode's liability exceed the Software license price as indi
82
82
 
83
83
  13.5 Indemnification. You agree to defend, indemnify, and hold harmless ShakaCode from and against any lawsuits, claims, losses, damages, fines and expenses (including attorneys' fees and costs) arising out of your use of the Software or breach of this Agreement.
84
84
 
85
- 13.6 Governing Law. This Agreement is governed by the laws of the State of Oregon and the United States without regard to conflicts of laws provisions thereof, and without regard to the United Nations Convention on the International Sale of Goods or the Uniform Computer Information Transactions Act, as currently enacted by any jurisdiction or as may be codified or amended from time to time by any jurisdiction. The jurisdiction and venue for actions related to the subject matter hereof shall be the state of Oregon and United States federal courts located in Portland, Oregon, and both parties hereby submit to the personal jurisdiction of such courts.
85
+ 13.6 Governing Law. This Agreement is governed by the laws of the State of Hawaii and the United States without regard to conflicts of laws provisions thereof, and without regard to the United Nations Convention on the International Sale of Goods or the Uniform Computer Information Transactions Act, as currently enacted by any jurisdiction or as may be codified or amended from time to time by any jurisdiction. The jurisdiction and venue for actions related to the subject matter hereof shall be the state of Hawaii and United States federal courts located in Kahului, Hawaii, and both parties hereby submit to the personal jurisdiction of such courts.
86
86
 
87
87
  13.7 Attorneys’ Fees and Costs. The prevailing party in any action to enforce this Agreement will be entitled to recover its attorneys’ fees and costs in connection with such action.
88
88
 
data/README.md CHANGED
@@ -11,6 +11,15 @@
11
11
 
12
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)
13
13
 
14
+ # News
15
+ * ShakaCode now maintains the official successor to `rails/webpacker`, [`shakapacker`](https://github.com/shakacode/shakapacker).
16
+ * Project is updated to support Rails 7!
17
+ * **React and Webpack with Ruby on Rails**: The current version of https://github.com/rails/webpacker will soon ship. While it won't be the default for Rails 7, it is not "deprecated." The core webpack configuration has become slimmer, allowing easier extension. If you want to get started today, use the master branch of [shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh) with `gem "webpacker", "6.0.0.rc.6"` Any updates to get to v6 from this point forward should be simple.
18
+
19
+ If you have time, please comment on Justin's final proposals for Webpacker v6: [webpacker/pulls/justin808](https://github.com/rails/webpacker/pulls/justin808).
20
+
21
+ -----
22
+
14
23
  *These are the docs for React on Rails 12. To see the version 11 docs, [click here](https://github.com/shakacode/react_on_rails/tree/11.3.0).*
15
24
 
16
25
  #### About
@@ -18,20 +27,20 @@ React on Rails integrates Rails with (server rendering of) Facebook's [React](ht
18
27
 
19
28
  This project is maintained by the software consulting firm [ShakaCode](https://www.shakacode.com). We focus on Ruby on Rails applications with React front-ends, often using TypeScript or ReScript (ReasonML). We also build React Native apps and Gatsby sites. See [our recent work](https://www.shakacode.com/recent-work) for examples of what we do. ShakaCode.com (HiChee.com) is [hiring developers that like working on open-source](https://www.shakacode.com/career/).
20
29
 
21
- Interested in optimizing your webpack setup for React on Rails including code
30
+ Are you interested in optimizing your webpack setup for React on Rails including code
22
31
  splitting with [react-router](https://github.com/ReactTraining/react-router#readme) and
23
32
  [loadable-components](https://loadable-components.com/) with server-side rendering for SEO and hot-reloading for developers?
24
- We 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/). Check out [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/).
33
+ We 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/). Several years later, Popmenu is serving millions of SSR requests per day React on Rails.
25
34
 
26
- Feel free to contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com), maintainer of React on Rails, for more information.
35
+ Check out [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/). For more information, feel free to contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com), maintainer of React on Rails.
27
36
 
28
37
  # Documentation
29
38
 
30
- See the documentation at [shakacode.com/react-on-rails/docs](https://www.shakacode.com/react-on-rails/docs/).
39
+ See the documentation at **[shakacode.com/react-on-rails/docs](https://www.shakacode.com/react-on-rails/docs/)**.
31
40
 
32
41
  ## Project Objective
33
42
 
34
- 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-Side Rendering for better SEO and improved performance.
43
+ To provide a high performance framework for integrating Ruby on Rails with React via the [**Webpacker**](https://github.com/rails/webpacker) gem, especially regarding React Server-Side Rendering for better SEO and improved performance.
35
44
 
36
45
  ## Features and Why React on Rails?
37
46
 
@@ -47,7 +56,9 @@ Given that `rails/webpacker` gem already provides basic React integration, why w
47
56
 
48
57
  See [Rails/Webpacker React Integration Options](https://www.shakacode.com/react-on-rails/docs/guides/rails-webpacker-react-integration-options) for comparisons to other gems.
49
58
 
50
- See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
59
+ ## Online demo
60
+ * See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
61
+ * A deployed version of the project `spec/dummy` which demonstrates several uses of `react_on_rails` is available on heroku [through this link](https://ror-spec-dummy.herokuapp.com/)
51
62
 
52
63
  ## ShakaCode Forum Premium Content
53
64
  _Requires creating a free account._
@@ -55,20 +66,19 @@ _Requires creating a free account._
55
66
  * [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)
56
67
  * [How to conditionally render server side based on the device type](https://forum.shakacode.com/t/how-to-conditionally-render-server-side-based-on-the-device-type/1473)
57
68
 
58
-
59
69
  ## Prerequisites
60
70
 
61
- Ruby on Rails >=5 and rails/webpacker 4.2+.
71
+ Ruby on Rails >=5, rails/webpacker >= 4.2, Ruby >= 2.7
62
72
 
63
73
  # Support
64
74
 
65
75
  * [Click to join **React + Rails Slack**](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
66
76
  - [**Subscribe**](https://app.mailerlite.com/webforms/landing/l1d9x5) for announcements of new releases of React on Rails and of our latest [blog articles](https://blog.shakacode.com) and tutorials.
67
- - **[forum.shakacode.com](https://forum.shakacode.com)**: Post your questions
77
+ - [Discussions](https://github.com/shakacode/react_on_rails/discussions): Post your questions regarding React on Rails
78
+ - **[forum.shakacode.com](https://forum.shakacode.com)**: Other discussions
68
79
  - **[@railsonmaui on Twitter](https://twitter.com/railsonmaui)**
69
80
  - *See [NEWS.md](https://github.com/shakacode/react_on_rails/tree/master/NEWS.md) for more notes over time.*
70
81
  - See [Projects](https://github.com/shakacode/react_on_rails/tree/master/PROJECTS.md) using and [KUDOS](https://github.com/shakacode/react_on_rails/tree/master/KUDOS.md) for React on Rails. Please submit yours! Please edit either page or [email us](mailto:contact@shakacode.com) and we'll add your info. We also **love stars** as it helps us attract new users and contributors.
71
- - *See [NEWS.md](https://github.com/shakacode/react_on_rails/tree/master/NEWS.md) for more notes over time.*
72
82
 
73
83
  ## Contributing
74
84
 
@@ -85,12 +95,12 @@ The following companies support this open source project, and ShakaCode uses the
85
95
  [![HoneyBadger](https://user-images.githubusercontent.com/1118459/114100696-63962a00-9860-11eb-8ac1-75ca02856d8e.png)](https://www.honeybadger.io/)
86
96
  [![StatusHero](https://user-images.githubusercontent.com/1118459/126868048-3fe64e54-4d6d-4066-9df2-8cf6fbaeb314.png)](https://statushero.com/)
87
97
 
88
- ShakaCode's favorite project tracking tool is [ClubHouse](https://clubhouse.io/). 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/referral/). By using our [referral code](http://r.clbh.se/mvfoNeH) you'll be supporting ShakaCode and, thus, React on Rails!
98
+ ShakaCode's favorite project tracking tool is [Shortcut](https://shortcut.com/). If you want to **try Shortcut 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/referral/). By using our [referral code](http://r.clbh.se/mvfoNeH) you'll be supporting ShakaCode and, thus, React on Rails!
89
99
 
90
100
  Aloha and best wishes from Justin and the ShakaCode team!
91
101
 
92
102
  # Work with Us
93
- ShakaCode is **[hiring passionate software engineers](http://www.shakacode.com/career)** to work on our projects, including [HiChee](https://hichee.com).
103
+ ShakaCode is **[hiring passionate software engineers](http://www.shakacode.com/career)** to work on our projects, including [HiChee](https://hichee.com)!
94
104
 
95
105
  # License
96
106
 
data/SUMMARY.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Table of Contents
2
2
 
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**
3
12
  + [Home](./README.md)
4
13
 
5
14
  ## **Basics**
@@ -16,9 +16,20 @@ For more information, see [Using Multiple Buildpacks for an App](https://devcent
16
16
 
17
17
  ### rails/webpacker webpack configuration
18
18
  If you're using the standard rails/webpacker configuration of webpack, then rails/webpacker
19
- will automatically modify or create an assets:precompile task to build your assets.
19
+ will automatically modify or create an assets:precompile task to build your assets.
20
20
 
21
- ### custom webpack configuration
22
- If you're a custom webpack configuration, and you **do not have the default
23
- `config/webpack/production.js`** file, then the `config/initializers/react_on_rails.rb`
24
- configuration `config.build_production_command` will be used.
21
+ Alternatively, you can specify `config.build_production_command` to have
22
+ react_on_rails invoke a command for you during assets:precompile.
23
+
24
+ ```
25
+ config.build_production_command = "RAILS_ENV=production bin/webpack"
26
+ ```
27
+
28
+ ### Consider Removing Webpacker's clean task
29
+
30
+ If you are deploying on Heroku, then you don't need Webpacker's clean task which
31
+ might delete files that you need.
32
+
33
+ ```
34
+ Rake::Task['webpacker:clean'].clear
35
+ ```
@@ -66,15 +66,14 @@ ReactOnRails.configure do |config|
66
66
  # defaults to "" (top level)
67
67
  config.node_modules_location = "client" # If using webpacker you should use "".
68
68
 
69
- # This configures the script to run to build the production assets by webpack . Set this to nil
70
- # if you don't want react_on_rails building this file for you.
71
- # Note, if you want to use this command then you should remove the file
72
- # config/webpack/production.js
73
- # If that file exists, React on Rails thinks that you'll use the rails/webpacker bin/webpack compiler.
69
+ # If you're using the standard rails/webpacker configuration of webpack, then rails/webpacker
70
+ # will automatically modify or create an assets:precompile task to build your assets. If so,
71
+ # set this value to nil. Alternatively, you can specify `config.build_production_command`
72
+ # to have react_on_rails invoke a command for you during assets:precompile.
73
+ # The command is either a script or a module containing a class method `call`
74
+ # In this example, the module BuildProductionCommand would have a class method `call`.
74
75
  config.build_production_command = "RAILS_ENV=production bin/webpack"
75
76
 
76
- # Alternatively, you can also specify a module containing a class method `call`
77
- # In this example, the module BuildProductionCommand would have a class method `call`.
78
77
  # See bottom for an example of the BuildProductionCommand module.
79
78
  # config.build_production_command = BuildProductionCommand
80
79
  # If you wish to utilize ReactOnRailsPro production bundle caching logic, then use
@@ -86,7 +85,7 @@ ReactOnRails.configure do |config|
86
85
  # SERVER RENDERING OPTIONS
87
86
  ################################################################################
88
87
  # This is the file used for server rendering of React when using `(prerender: true)`
89
- # If you are never using server rendering, you should set this to "".
88
+ # If you are not using server rendering, you should set this to `nil`.
90
89
  # Note, there is only one server bundle, unlike JavaScript where you want to minimize the size
91
90
  # of the JS sent to the client. For the server rendering, React on Rails creates a pool of
92
91
  # JavaScript execution instances which should handle any component requested.
@@ -130,6 +129,11 @@ ReactOnRails.configure do |config|
130
129
  # any server rendering issues immediately during development.
131
130
  config.raise_on_prerender_error = Rails.env.development?
132
131
 
132
+ # This configuration allows logic to be applied to client rendered props, such as stripping props that are only used during server rendering.
133
+ # Add a module with an adjust_props_for_client_side_hydration method that expects the component's name & props hash
134
+ # See below for an example definition of RenderingPropsExtension
135
+ config.rendering_props_extension = RenderingPropsExtension
136
+
133
137
  ################################################################################
134
138
  # Server Renderer Configuration for ExecJS
135
139
  ################################################################################
@@ -177,9 +181,8 @@ ReactOnRails.configure do |config|
177
181
 
178
182
  # You can optionally add values to your rails_context. This object is passed
179
183
  # every time a component renders.
180
- # See example below for an example definition of RenderingExtension
181
- #
182
- # config.rendering_extension = RenderingExtension
184
+ # See below for an example definition of RenderingExtension
185
+ config.rendering_extension = RenderingExtension
183
186
 
184
187
  ################################################################################
185
188
  ################################################################################
@@ -217,12 +220,23 @@ ReactOnRails.configure do |config|
217
220
  end
218
221
  ```
219
222
 
223
+ Example of a ReactOnRailsConfig module for `client_props_extension`:
224
+
225
+ ```ruby
226
+ module RenderingPropsExtension
227
+ # The modify_props method will be called by ReactOnRails::ReactComponent::RenderOptions if config.client_props_extension is defined
228
+ def self.adjust_props_for_client_side_hydration(component_name, props)
229
+ component_name == 'HelloWorld' ? props.except(:server_side_only) : props
230
+ end
231
+ end
232
+ ```
233
+
220
234
  Example of a ReactOnRailsConfig module for `production_build_command`:
221
235
 
222
236
  ```ruby
223
237
  module BuildProductionCommand
224
238
  include FileUtils
225
- # Method with the name of call will be called during assets:precompile
239
+ # The call method will be called during assets:precompile
226
240
  def self.call
227
241
  sh "bin/webpack"
228
242
  end
@@ -35,7 +35,6 @@ For example, you might create a [Procfile.dev](https://github.com/shakacode/reac
35
35
  On production deployments that use asset precompilation, such as Heroku deployments, `rails/webpacker`, by default, will automatically run webpack to build your JavaScript bundles, running the command `bin/webpack` in your app.
36
36
 
37
37
  However, if you want to run a custom command to run webpack to build your bundles, then you will:
38
- 1. Ensure you do not have a `config/webpack/production.js` file
39
38
  1. Define `config.build_production_command` in your [config/initializers/react_on_rails.rb](https://www.shakacode.com/react-on-rails/docs/guides/configuration/)
40
39
 
41
40
  Then React on Rails modifies the `assets:precompile` task to run your `build_production_command`.
@@ -4,7 +4,7 @@
4
4
 
5
5
  -----
6
6
 
7
- *Updated for Ruby 2.7.1, Rails 6.0.3.1, and React on Rails v12.0.0*
7
+ *Updated for Ruby 2.7.1, Rails 6.0.3.1, React on Rails v12.5.0, and Webpacker v6*
8
8
 
9
9
  This tutorial guides you through setting up a new or existing Rails app with **React on Rails**, demonstrating Rails + React + Redux + Server Rendering.
10
10
 
@@ -42,7 +42,7 @@ gem install foreman # download and install Foreman
42
42
  ```
43
43
 
44
44
  ## Create a new Ruby on Rails App
45
- Then we need to create a fresh Rails application with webpacker react support as following.
45
+ Then we need to create a fresh Rails application as following.
46
46
 
47
47
  First be sure to run `rails -v` and check you are using Rails 5.1.3 or above. If you are using an older version of Rails, you'll need to install webpacker with react per the instructions [here](https://github.com/rails/webpacker).
48
48
 
@@ -51,10 +51,9 @@ cd <directory where you want to create your new Rails app>
51
51
 
52
52
  # Any name you like for the rails app
53
53
  # Skip javascript so will add that next and get the current version
54
- rails new --skip-sprockets -J --skip-turbolinks test-react-on-rails-v12-no-sprockets
54
+ rails new --skip-sprockets --skip-turbolinks --javascript=webpack test-react-on-rails
55
55
 
56
56
  cd test-react-on-rails
57
- bundle
58
57
  ```
59
58
 
60
59
  ## Add the webpacker and react_on_rails gems
@@ -63,22 +62,21 @@ of both the gem and npm package. In other words, don't use the `^` or `~` in the
63
62
  _Use the latest version for react_on_rails._
64
63
 
65
64
  ```
66
- gem 'react_on_rails', '12.0.4' # prefer exact gem version to match npm version
65
+ gem 'react_on_rails', '12.5.0' # prefer exact gem version to match npm version
67
66
  ```
68
67
 
69
68
  Note: The latest released React On Rails version is considered stable. Please use the latest
70
69
  version to ensure you get all the security patches and the best support.
71
70
 
72
71
  ```bash
73
- bundle add webpacker
74
- bundle add react_on_rails --version=12.0.4 --strict
72
+ bundle add webpacker --git=https://github.com/rails/webpacker.git
73
+ bundle add react_on_rails --version=12.5.0 --strict
75
74
  ```
76
75
 
77
76
  ## Run the webpacker generator
78
77
 
79
- ```
78
+ ```terminal
80
79
  bundle exec rails webpacker:install
81
- bundle exec rails webpacker:install:react
82
80
  ```
83
81
 
84
82
  Let's commit everything before installing React on Rails.
@@ -97,20 +95,24 @@ Install React on Rails: `rails generate react_on_rails:install`. You need to fir
97
95
  Note, using `redux` is no longer recommended as the basic installer uses React Hooks.
98
96
  If you want the redux install: `rails generate react_on_rails:install --redux`
99
97
 
98
+ The generator will add `mini_racer`'s latest version. If you're using linux & encounter issues installing `libv8`, here's [a common solution](https://github.com/rubyjs/mini_racer/issues/218).
99
+
100
100
  ```
101
101
  rails generate react_on_rails:install
102
102
  ```
103
103
 
104
- Then run server with a static client bundle. Static means that the bundle is saved in your
105
- public/webpack/packs directory.
104
+ Enter `a` to replace all configuration files required by the project.
106
105
 
106
+ Then run the server with one of the following options:
107
+
108
+ ## Running with HMR
107
109
  ```
108
110
  foreman start -f Procfile.dev
109
111
  ```
110
112
 
111
- ## To run with the webpack-dev-server:
113
+ ## Running without HMR, statically creating the bundles
112
114
  ```
113
- foreman start -f Procfile.dev-hmr
115
+ foreman start -f Procfile.dev-static
114
116
  ```
115
117
 
116
118
  Visit [http://localhost:3000/hello_world](http://localhost:3000/hello_world) and see your **React On Rails** app running!
@@ -250,6 +252,8 @@ heroku open
250
252
 
251
253
  and you will see your live app and you can share this URL with your friends. Congrats!
252
254
 
255
+ A deployed version of the project `spec/dummy` which demonstrates several uses of `react_on_rails` is available on heroku [through this link](https://ror-spec-dummy.herokuapp.com/)
256
+
253
257
  ## Turning on Server Rendering
254
258
 
255
259
  You can turn on server rendering by simply changing the `prerender` option to `true`:
@@ -312,7 +316,7 @@ mv app/javascript client
312
316
 
313
317
  ## Using HMR with the rails/webpacker setup
314
318
 
315
- Start the app using `foreman start -f Procfile.dev-hmr`.
319
+ Start the app using `foreman start -f Procfile.dev`.
316
320
 
317
321
  When you change a JSX file and save, the browser will automatically refresh!
318
322
 
@@ -33,7 +33,40 @@ module ReactOnRails
33
33
  app/views/layouts/hello_world.html.erb
34
34
  config/initializers/react_on_rails.rb
35
35
  Procfile.dev
36
- Procfile.dev-hmr]
36
+ Procfile.dev-static]
37
+ base_files.each { |file| copy_file("#{base_path}#{file}", file) }
38
+ end
39
+
40
+ def copy_js_bundle_files
41
+ base_path = "base/base/"
42
+ base_files = %w[app/javascript/packs/server-bundle.js
43
+ app/javascript/bundles/HelloWorld/components/HelloWorldServer.js
44
+ app/javascript/bundles/HelloWorld/components/HelloWorld.module.css]
45
+ base_files.each { |file| copy_file("#{base_path}#{file}", file) }
46
+ end
47
+
48
+ def copy_webpack_config
49
+ puts "Adding Webpack config"
50
+ base_path = "base/base"
51
+ base_files = %w[babel.config.js
52
+ config/webpack/clientWebpackConfig.js
53
+ config/webpack/commonWebpackConfig.js
54
+ config/webpack/development.js
55
+ config/webpack/production.js
56
+ config/webpack/serverWebpackConfig.js
57
+ config/webpack/webpackConfig.js]
58
+ config = {
59
+ message: "// The source code including full typescript support is available at:"
60
+ }
61
+ base_files.each do |file|
62
+ template("#{base_path}/#{file}.tt", file, config)
63
+ end
64
+ end
65
+
66
+ def copy_webpacker_config
67
+ puts "Adding Webpacker v6 config"
68
+ base_path = "base/base/"
69
+ base_files = %w[config/webpacker.yml]
37
70
  base_files.each { |file| copy_file("#{base_path}#{file}", file) }
38
71
  end
39
72
 
@@ -51,6 +84,16 @@ module ReactOnRails
51
84
  puts "Adding the lastest react-on-rails NPM module. Double check this is correct in package.json"
52
85
  run "yarn add react-on-rails --exact"
53
86
  end
87
+
88
+ puts "Adding React dependencies"
89
+ run "yarn add react react-dom @babel/preset-react prop-types babel-plugin-transform-react-remove-prop-types \
90
+ babel-plugin-macros"
91
+
92
+ puts "Adding CSS handlers"
93
+ run "yarn add css-loader css-minimizer-webpack-plugin mini-css-extract-plugin style-loader"
94
+
95
+ puts "Adding dev dependencies"
96
+ run "yarn add -D @pmmmwh/react-refresh-webpack-plugin react-refresh"
54
97
  end
55
98
 
56
99
  def append_to_spec_rails_helper
@@ -111,10 +154,10 @@ module ReactOnRails
111
154
  - Alternately, you may turn off compile in config/webpacker.yml and run the foreman
112
155
  command to start the rails server and run webpack in watch mode.
113
156
 
114
- foreman start -f Procfile.dev
157
+ foreman start -f Procfile.dev-static
115
158
 
116
159
  - To turn on HMR, edit config/webpacker.yml and set HMR to true. Restart the rails server
117
- and bin/webpack-dev-server. Or use Procfile.dev-hmr.
160
+ and bin/webpack-dev-server. Or use Procfile.dev.
118
161
 
119
162
  - To server render, change this line app/views/hello_world/index.html.erb to
120
163
  `prerender: true` to see server rendering (right click on page and select "view source").
@@ -52,4 +52,8 @@ module GeneratorHelper
52
52
  empty_directory(parent_directories) unless dest_dir_exists?(parent_directories)
53
53
  copy_file source_file, destination_file
54
54
  end
55
+
56
+ def add_documentation_reference(message, source)
57
+ "#{message} \n#{source}"
58
+ end
55
59
  end