react_on_rails 13.0.2 → 13.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -4
  3. data/Gemfile.development_dependencies +1 -3
  4. data/README.md +42 -19
  5. data/docs/additional-details/migrating-from-react-rails.md +1 -1
  6. data/docs/api/view-helpers-api.md +2 -1
  7. data/docs/{guides/getting-started.md → getting-started.md} +4 -1
  8. data/docs/guides/client-vs-server-rendering.md +4 -2
  9. data/docs/guides/configuration.md +18 -4
  10. data/docs/guides/file-system-based-automated-bundle-generation.md +188 -0
  11. data/docs/guides/i18n.md +71 -83
  12. data/docs/guides/tutorial.md +9 -3
  13. data/docs/home.md +1 -1
  14. data/docs/javascript/server-rendering-tips.md +0 -3
  15. data/lib/generators/react_on_rails/base_generator.rb +0 -1
  16. data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb +1 -1
  17. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +13 -0
  18. data/lib/react_on_rails/configuration.rb +11 -33
  19. data/lib/react_on_rails/helper.rb +37 -2
  20. data/lib/react_on_rails/locales/base.rb +24 -1
  21. data/lib/react_on_rails/packs_generator.rb +298 -0
  22. data/lib/react_on_rails/react_component/render_options.rb +4 -0
  23. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +0 -6
  24. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +2 -0
  25. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +19 -3
  26. data/lib/react_on_rails/version.rb +1 -1
  27. data/lib/react_on_rails/webpacker_utils.rb +14 -0
  28. data/lib/react_on_rails.rb +1 -0
  29. data/lib/tasks/generate_packs.rake +11 -0
  30. data/package.json +2 -2
  31. data/yarn.lock +5 -5
  32. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70b55160147309cf5da5f36f8d1f23ebad08c70b5d13362acc38ed1c6fbcd780
4
- data.tar.gz: d6635ba54093daec5ee69412f46b0751d18dd035e37c69886625e94f3bc24728
3
+ metadata.gz: 67d4584eb27dc3faa475b108565c57f201da8be1b50959f280c1e9904d22e891
4
+ data.tar.gz: c1d0c37d9cf8be39c87b7976466c10d72837f7b777b39b5b1d3771fb1602c097
5
5
  SHA512:
6
- metadata.gz: bffe017f74585f13ddb5a647d0684b778e48fc40ebf62e586d0b1091cfa04716602a1fa54c21118fc0b43e2d4d9b6d65b9a5c333c3ea6b31ad2a90b9e7675a60
7
- data.tar.gz: 2ea465e9a7cc0da248743bade989b811f1703371ca8dd757e9b072cb6b30106e4ebf2cc9351f742d4b8c63782b0b101183ca676733418df0d12677a84f05ccec
6
+ metadata.gz: 8ddc27d5e684c33d23234221989fa04ba4c46a44ade8593a392e2444feb4b569a74334c3b704ff4124bc6ae89a8ca9210736ea37afb6e11e574c3aadafb2e0f4
7
+ data.tar.gz: bbcdae693b9cad8f964ec85b89a61ad656b2192ee5b26476d039d3328d31eb47fd6c91e361b31d4ab68a2647477dcfb2d631b98a771e6d956ea44523aa55309d
data/CHANGELOG.md CHANGED
@@ -16,10 +16,38 @@ Please follow the recommendations outlined at [keepachangelog.com](http://keepac
16
16
  Changes since last non-beta release.
17
17
 
18
18
  *Please add entries here for your pull requests that are not yet released.*
19
+
20
+ ### [13.1.0] - 2022-08-20
21
+
22
+ #### Improved
23
+ - Removed addition of `mini_racer` gem by default. [PR 1453](https://github.com/shakacode/react_on_rails/pull/1453) by [vtamara](https://github.com/vtamara) and [tomdracz](https://github.com/tomdracz).
24
+
25
+ Using `mini_racer` makes most sense when deploying or building in environments that do not have Javascript runtime present. Since `react_on_rails` requires Node.js, there's no reason to override `ExecJS` runtime with `mini_racer`.
26
+
27
+ To migrate this change, remove `mini_racer` gem from your `Gemfile` and test your app for correct behaviour. You can continue using `mini_racer` and it will be still picked as the default `ExecJS` runtime, if present in your app `Gemfile`.
28
+
29
+ - Upgraded the example test app in `spec/dummy` to React 18. [PR 1463](https://github.com/shakacode/react_on_rails/pull/1463) by [alexeyr](https://github.com/alexeyr).
30
+
31
+ - Added file-system-based automatic bundle generation feature. [PR 1455](https://github.com/shakacode/react_on_rails/pull/1455) by [pulkitkkr](https://github.com/pulkitkkr).
32
+
33
+ #### Fixed
34
+ - Correctly unmount roots under React 18. [PR 1466](https://github.com/shakacode/react_on_rails/pull/1466) by [alexeyr](https://github.com/alexeyr).
35
+
36
+ - Fixed the `You are importing hydrateRoot from "react-dom" [...] You should instead import it from "react-dom/client"` warning under React 18 ([#1441](https://github.com/shakacode/react_on_rails/issues/1441)). [PR 1460](https://github.com/shakacode/react_on_rails/pull/1460) by [alexeyr](https://github.com/alexeyr).
37
+
38
+ In exchange, you may see a warning like this when building a Webpack bundle under React 16:
39
+ ```
40
+ WARNING in ./node_modules/react-on-rails/node_package/lib/reactHydrateOrRender.js19:25-52
41
+ Module not found: Error: Can't resolve 'react-dom/client' in '/home/runner/work/react_on_rails/react_on_rails/spec/dummy/node_modules/react-on-rails/node_package/lib'
42
+ @ ./node_modules/react-on-rails/node_package/lib/ReactOnRails.js 34:45-78
43
+ @ ./client/app/packs/client-bundle.js 5:0-42 32:0-23 35:0-21 59:0-26
44
+ ```
45
+ It can be safely [suppressed](https://webpack.js.org/configuration/other-options/#ignorewarnings) in your Webpack configuration.
46
+
19
47
  ### [13.0.2] - 2022-03-09
20
48
  #### Fixed
21
49
  - React 16 doesn't support version property, causing problems loading React on Rails. [PR 1435](https://github.com/shakacode/react_on_rails/pull/1435) by [justin808](https://github.com/justin808).
22
-
50
+
23
51
  ### [13.0.1] - 2022-02-09
24
52
  #### Improved
25
53
  - Updated the default generator. [PR 1431](https://github.com/shakacode/react_on_rails/pull/1431) by [justin808](https://github.com/justin808).
@@ -29,7 +57,7 @@ Changes since last non-beta release.
29
57
  - Removed webpacker as a dependency. Add gem Shakapacker to your project, and update your package.json to also use shakapacker.
30
58
 
31
59
  #### Fixed
32
- - Propper throwing of exceptions.
60
+ - Proper throwing of exceptions.
33
61
  - Default configuration better handles test env.
34
62
 
35
63
  ### [12.6.0] - 2022-01-22
@@ -63,7 +91,7 @@ Changes since last non-beta release.
63
91
 
64
92
  - Ability to stop React on Rails from modifying or creating the `assets:precompile` task. [PR 1371](https://github.com/shakacode/react_on_rails/pull/1371) by [justin808](https://github.com/justin808). Thanks to [elstgav](https://github.com/elstgav) for [the suggestion](https://github.com/shakacode/react_on_rails/issues/1368)!
65
93
 
66
- - Ability to stop stubbing of setTimeout, setInterval, & clearTimeout conditional by setting `ReactOnRailsPro.config.include_execjs_polyfills = false` in the React on Rails Pro configuration file. Also, added the ability to have render functions return a promise to be awaited by React on Rails Pro Node Renderer. [PR 1380](https://github.com/shakacode/react_on_rails/pull/1380) by [judahmeek](https://github.com/judahmeek)
94
+ - Added the ability to have render functions return a promise to be awaited by React on Rails Pro Node Renderer. [PR 1380](https://github.com/shakacode/react_on_rails/pull/1380) by [judahmeek](https://github.com/judahmeek)
67
95
 
68
96
  ### [12.3.0] - 2021-07-26
69
97
  #### Added
@@ -1014,7 +1042,9 @@ Best done with Object destructing:
1014
1042
  ##### Fixed
1015
1043
  - Fix several generator related issues.
1016
1044
 
1017
- [Unreleased]: https://github.com/shakacode/react_on_rails/compare/13.0.1...master
1045
+ [Unreleased]: https://github.com/shakacode/react_on_rails/compare/13.0.2...master
1046
+ [13.1.0]: https://github.com/shakacode/react_on_rails/compare/13.0.2...13.1.0
1047
+ [13.0.2]: https://github.com/shakacode/react_on_rails/compare/13.0.1...13.0.2
1018
1048
  [13.0.1]: https://github.com/shakacode/react_on_rails/compare/13.0.0...13.0.1
1019
1049
  [13.0.0]: https://github.com/shakacode/react_on_rails/compare/12.6.0...13.0.0
1020
1050
  [12.6.0]: https://github.com/shakacode/react_on_rails/compare/12.5.2...12.6.0
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- gem "shakapacker", ">= 6.1.1"
3
+ gem "shakapacker", ">= 6.4.0"
4
4
  gem "bootsnap", require: false
5
5
  gem "rails", "~> 7.0"
6
6
  gem "sqlite3"
@@ -21,8 +21,6 @@ gem "sprockets", "~> 4.0"
21
21
 
22
22
  gem "amazing_print"
23
23
 
24
- gem "mini_racer", ">= 0.6.2"
25
-
26
24
  group :development, :test do
27
25
  gem "listen"
28
26
  gem "pry"
data/README.md CHANGED
@@ -9,7 +9,12 @@
9
9
 
10
10
  ---
11
11
 
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)
12
+ [![License](https://img.shields.io/badge/license-mit-green.svg)](LICENSE.md)[![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
+
14
+ [![Build Main](https://github.com/shakacode/react_on_rails/actions/workflows/main.yml/badge.svg)](https://github.com/shakacode/react_on_rails/actions/workflows/main.yml)
15
+ [![Build JS Tests](https://github.com/shakacode/react_on_rails/actions/workflows/package-js-tests.yml/badge.svg)](https://github.com/shakacode/react_on_rails/actions/workflows/package-js-tests.yml)
16
+ [![Build Rspec Tests](https://github.com/shakacode/react_on_rails/actions/workflows/rspec-package-specs.yml/badge.svg)](https://github.com/shakacode/react_on_rails/actions/workflows/rspec-package-specs.yml)
17
+ [![Linting](https://github.com/shakacode/react_on_rails/actions/workflows/lint-js-and-ruby.yml/badge.svg)](https://github.com/shakacode/react_on_rails/actions/workflows/lint-js-and-ruby.yml)
13
18
 
14
19
  # News
15
20
  * ShakaCode now maintains the official successor to `rails/webpacker`, [`shakapacker`](https://github.com/shakacode/shakapacker).
@@ -27,7 +32,7 @@ This project is maintained by the software consulting firm [ShakaCode](https://w
27
32
  Are you interested in optimizing your webpack setup for React on Rails including code
28
33
  splitting with [react-router](https://github.com/ReactTraining/react-router#readme) and
29
34
  [loadable-components](https://loadable-components.com/) with server-side rendering for SEO and hot-reloading for developers?
30
- 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.
35
+ 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 with React on Rails.
31
36
 
32
37
  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.
33
38
 
@@ -44,8 +49,9 @@ To provide a high performance framework for integrating Ruby on Rails with React
44
49
  Given that `rails/webpacker` gem already provides basic React integration, why would you use "React on Rails"?
45
50
 
46
51
  1. 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.
47
- 1. Tight integration with [shakapacker](https://github.com/shakacode/shakapacker) (or it's predecessor [rails/webpacker](https://github.com/rails/webpacker)).
52
+ Tight integration with [shakapacker](https://github.com/shakacode/shakapacker) (or it's predecessor [rails/webpacker](https://github.com/rails/webpacker)).
48
53
  1. Server-Side Rendering (SSR), often used for SEO crawler indexing and UX performance.
54
+ 1. [Automated optimized entry-point creation and bundle inclusion when placing a component on a page. With this feature, you no longer need to configure `javascript_pack_tags` and `stylesheet_pack_tags` on your layouts based on what’s shown. “It just works!”](https://www.shakacode.com/react-on-rails/docs/guides/file-system-based-automated-bundle-generation.md)
49
55
  1. [Redux](https://github.com/reactjs/redux) and [React Router](https://github.com/ReactTraining/react-router#readme) integration with server-side-rendering.
50
56
  1. [Internationalization (I18n) and (localization)](https://www.shakacode.com/react-on-rails/docs/guides/i18n)
51
57
  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+depth%3Aall/).
@@ -65,7 +71,7 @@ _Requires creating a free account._
65
71
 
66
72
  ## Prerequisites
67
73
 
68
- Ruby on Rails >=5, rails/webpacker >= 4.2, Ruby >= 2.7
74
+ Ruby on Rails >=5, rails/webpacker >= 4.2 or shakapacker > 6, Ruby >= 2.7
69
75
 
70
76
  # Support
71
77
 
@@ -81,24 +87,41 @@ Ruby on Rails >=5, rails/webpacker >= 4.2, Ruby >= 2.7
81
87
 
82
88
  Bug reports and pull requests are welcome. See [Contributing](https://github.com/shakacode/react_on_rails/tree/master/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).
83
89
 
84
- # Supporters
85
-
86
- 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 [HiChee.com](https://HiChee.com), [Rails AutoScale](https://railsautoscale.com) to scale the dynos of HiChee, and [HoneyBadger](https://www.honeybadger.io/) to monitor application errors. We love [BrowserStack](https://www.browserstack.com) to solve problems with oddball browsers. [Status Hero](https://statushero.com/) keeps the team posted on daily progress; it's so much better than live standups.
87
-
88
- [![RubyMine](https://user-images.githubusercontent.com/1118459/114100597-3b0e3000-9860-11eb-9b12-73beb1a184b2.png)](https://www.jetbrains.com/ruby/)
89
- [![Scout](https://user-images.githubusercontent.com/1118459/41828269-106b40f8-77d0-11e8-8d19-9c4b167ef9d8.png)](https://scoutapp.com/)
90
- [![Rails AutoScale](https://user-images.githubusercontent.com/1118459/103197530-48dc0e80-488a-11eb-8b1b-a16664b30274.png)](https://railsautoscale.com/)
91
- [![BrowserStack](https://cloud.githubusercontent.com/assets/1118459/23203304/1261e468-f886-11e6-819e-93b1a3f17da4.png)](https://www.browserstack.com)
92
- [![HoneyBadger](https://user-images.githubusercontent.com/1118459/114100696-63962a00-9860-11eb-8ac1-75ca02856d8e.png)](https://www.honeybadger.io/)
93
- [![StatusHero](https://user-images.githubusercontent.com/1118459/126868048-3fe64e54-4d6d-4066-9df2-8cf6fbaeb314.png)](https://statushero.com/)
94
-
95
- 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!
96
-
97
- Aloha and best wishes from Justin and the ShakaCode team!
98
-
99
90
  # Work with Us
100
91
  ShakaCode is **[hiring passionate software engineers](http://www.shakacode.com/career)** to work on our projects, including [HiChee](https://hichee.com)!
101
92
 
102
93
  # License
103
94
 
104
95
  The gem is available as open source under the terms of the [MIT License](https://github.com/shakacode/react_on_rails/tree/master/LICENSE.md).
96
+
97
+ # Supporters
98
+
99
+ <a href="https://www.jetbrains.com">
100
+ <img src="https://user-images.githubusercontent.com/4244251/184881139-42e4076b-024b-4b30-8c60-c3cd0e758c0a.png" alt="JetBrains" height="120px">
101
+ </a>
102
+ <a href="https://scoutapp.com">
103
+ <picture>
104
+ <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/4244251/184881147-0d077438-3978-40da-ace9-4f650d2efe2e.png">
105
+ <source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/4244251/184881152-9f2d8fba-88ac-4ba6-873b-22387f8711c5.png">
106
+ <img alt="ScoutAPM" src="https://user-images.githubusercontent.com/4244251/184881152-9f2d8fba-88ac-4ba6-873b-22387f8711c5.png" height="120px">
107
+ </picture>
108
+ </a>
109
+ <br />
110
+ <a href="https://www.browserstack.com">
111
+ <picture>
112
+ <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/4244251/184881122-407dcc29-df78-4b20-a9ad-f597b56f6cdb.png">
113
+ <source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/4244251/184881129-e1edf4b7-3ae1-4ea8-9e6d-3595cf01609e.png">
114
+ <img alt="BrowserStack" src="https://user-images.githubusercontent.com/4244251/184881129-e1edf4b7-3ae1-4ea8-9e6d-3595cf01609e.png" height="55px">
115
+ </picture>
116
+ </a>
117
+ <a href="https://railsautoscale.com">
118
+ <img src="https://user-images.githubusercontent.com/4244251/184881144-95c2c25c-9879-4069-864d-4e67d6ed39d2.png" alt="Rails Autoscale" height="55px">
119
+ </a>
120
+ <a href="https://www.honeybadger.io">
121
+ <img src="https://user-images.githubusercontent.com/4244251/184881133-79ee9c3c-8165-4852-958e-31687b9536f4.png" alt="Honeybadger" height="55px">
122
+ </a>
123
+
124
+ <br />
125
+ <br />
126
+
127
+ The following companies support our open source projects, and ShakaCode uses their products!
@@ -11,7 +11,7 @@ If you are using [react-rails](https://github.com/reactjs/react-rails) in your p
11
11
  //= require components
12
12
  ```
13
13
 
14
- - Follow our getting started guide: https://github.com/shakacode/react_on_rails#getting-started.
14
+ - Follow our [getting started guide](https://www.shakacode.com/react-on-rails/docs/getting-started/).
15
15
 
16
16
  Note: If you have components from react-rails you want to use, then you will need to port them into react_on_rails which uses webpack instead of the asset pipeline.
17
17
 
@@ -1,7 +1,7 @@
1
1
  # View and Controller Helpers
2
2
  ## View Helpers API
3
3
 
4
- Once the bundled files have been generated in your `app/assets/webpack` folder and you have registered your components, you will want to render these components on your Rails views using the included helper method, `react_component`.
4
+ Once the bundled files have been generated in your `app/assets/webpack` folder and you have registered your components, you will want to render these components on your Rails views using the included helper method, [`react_component`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component).
5
5
 
6
6
  ------------
7
7
 
@@ -27,6 +27,7 @@ Uncommonly used options:
27
27
  - **general options:**
28
28
  - **props:** Ruby Hash which contains the properties to pass to the react object, or a JSON string. If you pass a string, we'll escape it for you.
29
29
  - **prerender:** enable server-side rendering of a component. Set to false when debugging!
30
+ - **auto_load_bundle:** will automatically load the bundle for component by calling `append_javascript_pack_tag` and `append_stylesheet_pack_tag` under the hood.
30
31
  - **id:** Id for the div, will be used to attach the React component. This will get assigned automatically if you do not provide an id. Must be unique.
31
32
  - **html_options:** Any other HTML options get placed on the added div for the component. For example, you can set a class (or inline style) on the outer div so that it behaves like a span, with the styling of `display:inline-block`. You may also use an option of `tag: "span"` to replace the use of the default DIV tag to be a SPAN tag.
32
33
  - **trace:** set to true to print additional debugging information in the browser. Defaults to true for development, off otherwise. Only on the **client side** will you will see the `railsContext` and your props.
@@ -39,12 +39,15 @@ Note, the best way to understand how to use ReactOnRails is to study a few simpl
39
39
  With the code from running the React on Rails generator above:
40
40
 
41
41
  1. Edit `app/views/hello_world/index.html.erb` and set the `prerender` option to `true`.
42
+
43
+ You may need to use `Node` as your js runtime environment by setting `EXECJS_RUNTIME=Node` into your environment variables.
44
+
42
45
  2. Refresh the page.
43
46
 
44
47
  Below is the line where you turn server rendering on by setting `prerender` to true:
45
48
 
46
49
  ```erb
47
- <%= react_component("HelloWorld", props: @hello_world_props, prerender: false) %>
50
+ <%= react_component("HelloWorld", props: @hello_world_props, prerender: true) %>
48
51
  ```
49
52
 
50
53
  Note, if you got an error in your console regarding "ReferenceError: window is not defined",
@@ -4,9 +4,11 @@
4
4
 
5
5
  In most cases, you should use the `prerender: false` (default behavior) with the provided helper method to render the React component from your Rails views. In some cases, such as when SEO is vital, or many users will not have JavaScript enabled, you can enable server-rendering by passing `prerender: true` to your helper, or you can simply change the default in `config/initializers/react_on_rails`.
6
6
 
7
- Now the server will interpret your JavaScript. The default is to use [ExecJS](https://github.com/rails/execjs) and pass the resulting HTML to the client. We recommend using [mini_racer](https://github.com/discourse/mini_racer) as ExecJS's runtime.
7
+ Now the server will interpret your JavaScript. The default is to use [ExecJS](https://github.com/rails/execjs) and pass the resulting HTML to the client. By default, ExecJS uses the Node.js runtime. You can use alternative runtimes as outlined in [ExecJS readme](https://github.com/rails/execjs/blob/master/README.md).
8
8
 
9
- If you want to maximize the perfomance of your server rendering, then you want to use React on Rails Pro which uses NodeJS to do the server rendering. See the [docs for React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki).
9
+ Note: if you use the [mini_racer](https://github.com/rubyjs/mini_racer) runtime and run into a `ReferenceError: TextEncoder is not defined` error, see [this comment](https://github.com/shakacode/react_on_rails/issues/1457#issuecomment-1165026717) for a solution.
10
+
11
+ If you want to maximize the performance of your server rendering, then you want to use React on Rails Pro which uses NodeJS to do the server rendering. See the [docs for React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki).
10
12
 
11
13
  If you open the HTML source of any web page using React on Rails, you'll see the 3 parts of React on Rails rendering:
12
14
 
@@ -137,19 +137,33 @@ ReactOnRails.configure do |config|
137
137
  ################################################################################
138
138
  # Server Renderer Configuration for ExecJS
139
139
  ################################################################################
140
- # The default server rendering is ExecJS, probably using the mini_racer gem
140
+ # The default server rendering is ExecJS, by default using Node.js runtime
141
141
  # If you wish to use an alternative Node server rendering for higher performance,
142
142
  # contact justin@shakacode.com for details.
143
143
  #
144
144
  # For ExecJS:
145
145
  # You can configure your pool of JS virtual machines and specify where it should load code:
146
- # On MRI, use `mini_racer` for the best performance
147
- # (see [discussion](https://github.com/reactjs/react-rails/pull/290))
146
+ # On MRI, use `node.js` runtime for the best performance
147
+ # (see https://github.com/shakacode/react_on_rails/issues/1438)
148
+ # Also see https://github.com/shakacode/react_on_rails/issues/1457#issuecomment-1165026717 if using `mini_racer`
148
149
  # On MRI, you'll get a deadlock with `pool_size` > 1
149
150
  # If you're using JRuby, you can increase `pool_size` to have real multi-threaded rendering.
150
151
  config.server_renderer_pool_size = 1 # increase if you're on JRuby
151
152
  config.server_renderer_timeout = 20 # seconds
152
153
 
154
+ ################################################################################
155
+ ################################################################################
156
+ # FILE SYSTEM BASED COMPONENT REGISTRY
157
+ ################################################################################
158
+ # components_subdirectory is the name of the subdirectory matched to detect and register components automatically
159
+ # The default is nil. You can enable the feature by updating it in the next line.
160
+ config.components_subdirectory = "ror_components"
161
+
162
+ # For automated component registry, `render_component` view helper method tries to load bundle for component from
163
+ # generated directory. default is false, you can pass option at the time of individual usage or update the default
164
+ # in the following line
165
+ config.auto_load_bundle = false
166
+
153
167
  ################################################################################
154
168
  # I18N OPTIONS
155
169
  ################################################################################
@@ -173,7 +187,7 @@ ReactOnRails.configure do |config|
173
187
  ################################################################################
174
188
  ################################################################################
175
189
  # CLIENT RENDERING OPTIONS
176
- # Below options can be overriden by passing options to the react_on_rails
190
+ # Below options can be overridden by passing options to the react_on_rails
177
191
  # `render_component` view helper method.
178
192
  ################################################################################
179
193
  # default is false
@@ -0,0 +1,188 @@
1
+ # File-System-Based Automated Bundle Generation
2
+
3
+ To use the automated bundle generation feature introduced in React on Rails v13.1.0, please upgrade to use [Shakapacker v6.5.1](https://github.com/shakacode/shakapacker/tree/v6.5.1) at least. If you are currently using webpacker, please follow the migration steps available [here](https://github.com/shakacode/shakapacker/blob/master/docs/v6_upgrade.md).
4
+
5
+ ## Configuration
6
+
7
+ ### Enable nested_entries for Shakapacker
8
+ To use the automated bundle generation feature, set nested_entries: true in the webpacker.yml file like this. The generated files will go in a nested directory.
9
+
10
+ ```yml
11
+ default:
12
+ ...
13
+ nested_entries: true
14
+ ```
15
+
16
+ For more details, see [Configuration and Code](https://github.com/shakacode/shakapacker#configuration-and-code) section in [shakapacker](https://github.com/shakacode/shakapacker/).
17
+
18
+ ### Configure Components Subdirectory
19
+ `components_subdirectory` is the name of the matched directories containing components that will be automatically registered for use by the view helpers.
20
+ For example, configure `config/initializers/react_on_rails` to set the name for `components_subdirectory`.·
21
+
22
+ ```rb
23
+ config.components_subdirectory = "ror_components"
24
+ ```
25
+
26
+ Now all React components inside the directories called `ror_components` will automatically be registered for usage with [`react_component`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component) and [`react_component_hash`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component_hash) helper methods provided by React on Rails.
27
+
28
+ ### Configure `auto_load_bundle` Option
29
+
30
+ For automated component registry, [`react_component`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component) and [`react_component_hash`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component_hash) view helper method tries to load generated bundle for component from the generated directory automatically per `auto_load_bundle` option. `auto_load_bundle` option in `config/initializers/react_on_rails` configures the default value that will be passed to component helpers. The default is `false`, and the parameter can be passed explicitly for each call.
31
+
32
+ You can change the value in `config/initializers/react_on_rails` by updating it as follows:
33
+
34
+ ```rb
35
+ config.auto_load_bundle = true
36
+ ```
37
+
38
+ ### Update `.gitignore` file
39
+ React on Rails automatically generates pack files for components to be registered in the `packs/generated` directory. To avoid committing generated files into the version control system, please update `.gitignore` to have
40
+
41
+ ```gitignore
42
+ # Generated React on Rails packs
43
+ app/javascript/packs/generated
44
+ ```
45
+
46
+ *Note: the directory might be different depending on the `source_entry_path` in `config/webpacker.yml`.*
47
+
48
+ ## Usage
49
+
50
+ ### Basic usage
51
+
52
+ #### Background
53
+ If the `webpacker.yml` file is configured as instructed [here](https://github.com/shakacode/shakapacker#configuration-and-code), with the following configurations
54
+
55
+ ```yml
56
+ default: &default
57
+ source_path: app/javascript
58
+ source_entry_path: packs
59
+ public_root_path: public
60
+ public_output_path: packs
61
+ nested_entries: true
62
+ # And more
63
+ ```
64
+
65
+ the directory structure will look like this
66
+ ```
67
+ app/javascript:
68
+ └── packs: # sets up webpack entries
69
+ │ └── application.js # references FooComponentOne.jsx, BarComponentOne.jsx and BarComponentTwo.jsx in `../src`
70
+ └── src: # any directory name is fine. Referenced files need to be under source_path
71
+ │ └── Foo
72
+ │ │ └── ...
73
+ │ │ └── FooComponentOne.jsx
74
+ │ └── Bar
75
+ │ │ └── ...
76
+ │ │ └── BarComponentOne.jsx
77
+ │ │ └── BarComponentTwo.jsx
78
+ └── stylesheets:
79
+ │ └── my_styles.css
80
+ └── images:
81
+ └── logo.svg
82
+ ```
83
+
84
+ Previously, many applications would use one pack (webpack entrypoint) for many components. In this example, the`application.js` file manually registers server components, `FooComponentOne`, `BarComponentOne` and `BarComponentTwo`.
85
+
86
+ ```jsx
87
+ import ReactOnRails from 'react-on-rails';
88
+ import FooComponentOne from '../src/Foo/FooComponentOne';
89
+ import BarComponentOne from '../src/Foo/BarComponentOne';
90
+ import BarComponentTwo from '../src/Foo/BarComponentTwo';
91
+
92
+ ReactOnRails.register({ FooComponentOne, BarComponentOne, BarComponentTwo });
93
+ ```
94
+
95
+ Your layout would contain:
96
+
97
+ ```erb
98
+ <%= javascript_pack_tag 'application' %>
99
+ <%= stylesheet_pack_tag 'application' %>
100
+ ```
101
+
102
+
103
+ Suppose, you want to use bundle splitting to minimize unnecessary javascript loaded on each page, You would put each of your components in the `packs` directory.
104
+ ```
105
+ app/javascript:
106
+ └── packs: # sets up webpack entries
107
+ │ └── FooComponentOne.jsx # Internally uses ReactOnRails.register
108
+ │ └── BarComponentOne.jsx # Internally uses ReactOnRails.register
109
+ │ └── BarComponentTwo.jsx # Internally uses ReactOnRails.register
110
+ └── src: # any directory name is fine. Referenced files need to be under source_path
111
+ │ └── Foo
112
+ │ │ └── ...
113
+ │ └── Bar
114
+ │ │ └── ...
115
+ └── stylesheets:
116
+ │ └── my_styles.css
117
+ └── images:
118
+ └── logo.svg
119
+ ```
120
+
121
+ The tricky part is to figure out which bundles to load on any Rails view. [Shakapacker's `append_stylesheet_pack_tag` and `append_javascript_pack_tag` view helpers](https://github.com/shakacode/shakapacker#view-helper-append_javascript_pack_tag-and-append_stylesheet_pack_tag) enables Rails views to specify needed bundles for use by layout's call to `javascript_pack_tag` and `stylesheet_pack_tag`.
122
+
123
+ #### Solution
124
+
125
+ File-system-based automated pack generation simplifies this process with a new option for the view helpers. The steps to use it in this example are:
126
+
127
+ 1. Remove parameters passed directly to `javascript_pack_tag` and `stylesheet_pack_tag`.
128
+ 2. Remove parameters passed directly to `append_javascript_pack_tag` and `append_stylesheet_pack_tag`.
129
+
130
+ Your layout would now contain:
131
+
132
+ ```erb
133
+ <%= javascript_pack_tag %>
134
+ <%= stylesheet_pack_tag %>
135
+ ```
136
+
137
+ 3. Create a directory structure as mentioned below:
138
+
139
+ ```
140
+ app/javascript:
141
+ └── packs
142
+ └── src:
143
+ │ └── Foo
144
+ │ │ └── ...
145
+ │ │ └── ror_components # configured as `components_subdirectory`
146
+ │ │ └── FooComponentOne.jsx
147
+ │ └── Bar
148
+ │ │ └── ...
149
+ │ │ └── ror_components # configured as `components_subdirectory`
150
+ │ │ │ └── BarComponentOne.jsx
151
+ │ │ │ └── BarComponentTwo.jsx
152
+ ```
153
+
154
+ 4. You no longer need to register these React components nor directly add their bundles. For example you can have a Rails view using three components:
155
+
156
+ ```erb
157
+ <%= react_component("FooComponentOne", {}, auto_load_bundle: true) %>
158
+ <%= react_component("BarComponentOne", {}, auto_load_bundle: true) %>
159
+ <%= react_component("BarComponentTwo", {}, auto_load_bundle: true) %>
160
+ ```
161
+
162
+ If `FooComponentOne` uses multiple HTML strings for server rendering, the [`react_component_hash`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component_hash) view helper can be used on the Rails view, as illustrated below.
163
+
164
+ ```erb
165
+ <% foo_component_one_data = react_component_hash("FooComponentOne",
166
+ prerender: true,
167
+ auto_load_bundle: true
168
+ props: {}
169
+ ) %>
170
+ <% content_for :title do %>
171
+ <%= foo_component_one_data['title'] %>
172
+ <% end %>
173
+ <%= foo_component_one_data["componentHtml"] %>
174
+ ```
175
+
176
+ The default value of the `auto_load_bundle` parameter can be specified by setting `config.auto_load_bundle` in `config/initializers/react_on_rails.rb` and thus removed from each call to `react_component`.
177
+
178
+ ### Server Rendering and Client Rendering Components
179
+
180
+ If server rendering is enabled, the component will be registered for usage both in server and client rendering. In order to have separate definitions for client and server rendering, name the component files as `ComponentName.server.jsx` and `ComponentName.client.jsx`. The `ComponentName.server.jsx` file will be used for server rendering and the `ComponentName.client.jsx` file for client rendering. If you don't want the component rendered on the server, you should only have the `ComponentName.client.jsx` file.
181
+
182
+ *Note: If specifying separate definitions for client and server rendering, please make sure to delete the generalized `ComponentName.jsx` file.*
183
+
184
+ ### Using Automated Bundle Generation Feature with already defined packs
185
+
186
+ To use the Automated Bundle Generation feature with already defined packs, `config/initializers/react_on_rails` should explicitly be configured with `config.auto_load_bundle = false` and you can explicitly pass `auto_load_bundle` option in [`react_component`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component) and [`react_component_hash`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component_hash) for the components using this feature.
187
+
188
+