react_on_rails 13.1.0 → 13.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +5 -2
  3. data/.github/workflows/lint-js-and-ruby.yml +3 -3
  4. data/.github/workflows/main.yml +19 -13
  5. data/.github/workflows/package-js-tests.yml +2 -2
  6. data/.github/workflows/rspec-package-specs.yml +2 -2
  7. data/.rubocop.yml +4 -0
  8. data/CHANGELOG.md +21 -1
  9. data/Gemfile.development_dependencies +2 -2
  10. data/README.md +7 -5
  11. data/docs/api/javascript-api.md +9 -0
  12. data/docs/getting-started.md +15 -6
  13. data/docs/guides/configuration.md +25 -20
  14. data/docs/guides/file-system-based-automated-bundle-generation.md +16 -13
  15. data/docs/guides/installation-into-an-existing-rails-app.md +18 -20
  16. data/docs/guides/rails-webpacker-react-integration-options.md +8 -8
  17. data/docs/guides/react-server-rendering.md +1 -1
  18. data/docs/guides/tutorial.md +36 -32
  19. data/lib/generators/react_on_rails/base_generator.rb +15 -10
  20. data/lib/generators/react_on_rails/bin/dev +33 -0
  21. data/lib/generators/react_on_rails/bin/dev-static +33 -0
  22. data/lib/generators/react_on_rails/install_generator.rb +5 -0
  23. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +1 -1
  24. data/lib/react_on_rails/configuration.rb +40 -3
  25. data/lib/react_on_rails/helper.rb +21 -23
  26. data/lib/react_on_rails/packs_generator.rb +30 -101
  27. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +1 -1
  28. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +1 -20
  29. data/lib/react_on_rails/utils.rb +26 -0
  30. data/lib/react_on_rails/version.rb +1 -1
  31. data/lib/react_on_rails/webpacker_utils.rb +54 -3
  32. data/lib/tasks/generate_packs.rake +1 -1
  33. data/package.json +29 -28
  34. data/yarn.lock +2856 -3277
  35. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67d4584eb27dc3faa475b108565c57f201da8be1b50959f280c1e9904d22e891
4
- data.tar.gz: c1d0c37d9cf8be39c87b7976466c10d72837f7b777b39b5b1d3771fb1602c097
3
+ metadata.gz: e61be8a6315e32bd3127d5ed676e1235c9e44cb43ff011dde722947c4f18b518
4
+ data.tar.gz: 61be21f2eda6b8a58688af7a69f88b70c2b0dbfe23a9addf68f2894829e96787
5
5
  SHA512:
6
- metadata.gz: 8ddc27d5e684c33d23234221989fa04ba4c46a44ade8593a392e2444feb4b569a74334c3b704ff4124bc6ae89a8ca9210736ea37afb6e11e574c3aadafb2e0f4
7
- data.tar.gz: bbcdae693b9cad8f964ec85b89a61ad656b2192ee5b26476d039d3328d31eb47fd6c91e361b31d4ab68a2647477dcfb2d631b98a771e6d956ea44523aa55309d
6
+ metadata.gz: '069f91f435f7609c582a197e100e0140c9d4045b472fa163a06819847d860a339d0fba56ab408d32aa7307cb2b1205dfd5387b6e503810897a4898d6acf56dee'
7
+ data.tar.gz: ed764a94f2cf6b4ff1a50d605c73cab97371e0a0bc68bb344bc1978988c54b213b44cbc2bce6f6045158d662e7e8201e829f801df2a07392394dfcfcade3e3d4
data/.circleci/config.yml CHANGED
@@ -205,6 +205,9 @@ jobs:
205
205
  - run: *install-yalc-add-react-on-rails
206
206
  - run: *install-dummy-app-node-modules
207
207
  - run: *install-dummy-app-ruby-gems
208
+ - run:
209
+ name: generate file system-based packs
210
+ command: cd spec/dummy && bundle exec rake react_on_rails:generate_packs
208
211
  - run:
209
212
  name: Build test bundles for dummy app
210
213
  command: cd spec/dummy && yarn run build:test
@@ -269,12 +272,12 @@ jobs:
269
272
  name: Prep for CI
270
273
  # TODO -- need to leverage Circle CI containers
271
274
  command: |
272
- bundle exec rake prepare_for_ci
275
+ bundle exec rails prepare_for_ci
273
276
  - run:
274
277
  name: Main CI
275
278
  # TODO -- need to leverage Circle CI containers
276
279
  command: |
277
- bundle exec rake run_rspec:all_dummy
280
+ bundle exec rails run_rspec:all_dummy
278
281
  # The following step will run only if the main job is finished successfully.
279
282
  # Build hook is triggered by curl command described here https://docs.netlify.com/configure-builds/build-hooks/
280
283
  # NETLIFY_HOOK is an environment variable on CircleCI to keep sensitive data outside the repo
@@ -8,7 +8,7 @@ jobs:
8
8
  matrix:
9
9
  ruby: [2.7]
10
10
  node: [14]
11
- runs-on: ubuntu-latest
11
+ runs-on: ubuntu-22.04
12
12
  steps:
13
13
  - uses: actions/checkout@v2
14
14
  - name: Setup Ruby
@@ -32,12 +32,12 @@ jobs:
32
32
  uses: actions/cache@v2
33
33
  with:
34
34
  path: node_modules
35
- key: v4-package-node-modules-cache-${{ hashFiles('yarn.lock') }}
35
+ key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }}
36
36
  - name: Save root ruby gems to cache
37
37
  uses: actions/cache@v2
38
38
  with:
39
39
  path: vendor/bundle
40
- key: v4-package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}
40
+ key: v5-package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}
41
41
  - name: Install Node modules with Yarn for renderer package
42
42
  run: |
43
43
  yarn install --no-progress --no-emoji
@@ -8,13 +8,17 @@ jobs:
8
8
  matrix:
9
9
  ruby: [2.7]
10
10
  node: [14]
11
- runs-on: ubuntu-latest
11
+ runs-on: ubuntu-22.04
12
12
  steps:
13
13
  - uses: actions/checkout@v2
14
14
  - name: Setup Ruby
15
15
  uses: ruby/setup-ruby@v1
16
16
  with:
17
17
  ruby-version: ${{ matrix.ruby }}
18
+ # libyaml-dev is needed for psych v5
19
+ # this gem depends on sdoc which depends on rdoc which depends on psych
20
+ - name: Fix dependency for libyaml-dev
21
+ run: sudo apt install libyaml-dev
18
22
  - name: Setup Node
19
23
  uses: actions/setup-node@v2-beta
20
24
  with:
@@ -32,7 +36,7 @@ jobs:
32
36
  uses: actions/cache@v2
33
37
  with:
34
38
  path: node_modules
35
- key: v4-package-node-modules-cache-${{ hashFiles('yarn.lock') }}
39
+ key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }}
36
40
  - name: Install Node modules with Yarn for renderer package
37
41
  run: |
38
42
  yarn install --no-progress --no-emoji
@@ -44,7 +48,7 @@ jobs:
44
48
  uses: actions/cache@v2
45
49
  with:
46
50
  path: spec/dummy/node_modules
47
- key: v4-dummy-app-node-modules-cache-${{ hashFiles('spec/dummy/yarn.lock') }}
51
+ key: v5-dummy-app-node-modules-cache-${{ hashFiles('spec/dummy/yarn.lock') }}
48
52
  - name: yalc add react-on-rails
49
53
  run: cd spec/dummy && yalc add react-on-rails
50
54
  - name: Install Node modules with Yarn for dummy app
@@ -53,9 +57,11 @@ jobs:
53
57
  uses: actions/cache@v2
54
58
  with:
55
59
  path: spec/dummy/vendor/bundle
56
- key: v4-dummy-app-gem-cache-${{ hashFiles('spec/dummy/Gemfile.lock') }}
60
+ key: v5-dummy-app-gem-cache-${{ hashFiles('spec/dummy/Gemfile.lock') }}
57
61
  - name: Install Ruby Gems for dummy app
58
62
  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
63
+ - name: generate file system-based packs
64
+ run: cd spec/dummy && RAILS_ENV=test bundle exec rake react_on_rails:generate_packs
59
65
  - name: Build test bundles for dummy app
60
66
  run: cd spec/dummy && yarn run build:test
61
67
  - id: get-sha
@@ -64,7 +70,7 @@ jobs:
64
70
  uses: actions/cache@v2
65
71
  with:
66
72
  path: spec/dummy/public/webpack
67
- key: v4-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }}
73
+ key: v5-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }}
68
74
 
69
75
  main:
70
76
  needs: build-dummy-app-webpack-test-bundles
@@ -73,7 +79,7 @@ jobs:
73
79
  ruby: [2.7]
74
80
  node: [14]
75
81
  rake_task: ['run_rspec:all_dummy', 'run_rspec:all_but_examples', 'run_rspec:examples']
76
- runs-on: ubuntu-latest
82
+ runs-on: ubuntu-22.04
77
83
  steps:
78
84
  - uses: actions/checkout@v2
79
85
  - name: Setup Ruby
@@ -97,29 +103,29 @@ jobs:
97
103
  uses: actions/cache@v2
98
104
  with:
99
105
  path: node_modules
100
- key: v4-package-node-modules-cache-${{ hashFiles('yarn.lock') }}
106
+ key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }}
101
107
  - name: Save root ruby gems to cache
102
108
  uses: actions/cache@v2
103
109
  with:
104
110
  path: vendor/bundle
105
- key: v4-package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}
111
+ key: v5-package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}
106
112
  - name: Save dummy app ruby gems to cache
107
113
  uses: actions/cache@v2
108
114
  with:
109
115
  path: spec/dummy/vendor/bundle
110
- key: v4-dummy-app-gem-cache-${{ hashFiles('spec/dummy/Gemfile.lock') }}
116
+ key: v5-dummy-app-gem-cache-${{ hashFiles('spec/dummy/Gemfile.lock') }}
111
117
  - name: Save spec/dummy/node_modules to cache
112
118
  uses: actions/cache@v2
113
119
  with:
114
120
  path: spec/dummy/node_modules
115
- key: v4-dummy-app-node-modules-cache-${{ hashFiles('spec/dummy/yarn.lock') }}
121
+ key: v5-dummy-app-node-modules-cache-${{ hashFiles('spec/dummy/yarn.lock') }}
116
122
  - id: get-sha
117
123
  run: echo "::set-output name=sha::$(git rev-parse HEAD)"
118
124
  - name: Save test webpack bundles to cache (for build number checksum used by rspec job)
119
125
  uses: actions/cache@v2
120
126
  with:
121
127
  path: spec/dummy/public/webpack
122
- key: v4-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }}
128
+ key: v5-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }}
123
129
 
124
130
  - name: Install Node modules with Yarn for renderer package
125
131
  run: |
@@ -153,9 +159,9 @@ jobs:
153
159
  - name: Increase the amount of inotify watchers
154
160
  run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
155
161
  - name: Prep for CI
156
- run: bundle exec rake prepare_for_ci
162
+ run: bundle exec rails prepare_for_ci
157
163
  - name: Main CI
158
- run: bundle exec rake ${{ matrix.rake_task }}
164
+ run: bundle exec rails ${{ matrix.rake_task }}
159
165
  - name: Store test results
160
166
  uses: actions/upload-artifact@v2
161
167
  with:
@@ -7,7 +7,7 @@ jobs:
7
7
  strategy:
8
8
  matrix:
9
9
  node: [12, 14]
10
- runs-on: ubuntu-latest
10
+ runs-on: ubuntu-22.04
11
11
  steps:
12
12
  - uses: actions/checkout@v2
13
13
  - name: Setup Node
@@ -25,7 +25,7 @@ jobs:
25
25
  uses: actions/cache@v2
26
26
  with:
27
27
  path: node_modules
28
- key: v4-package-node-modules-cache-${{ hashFiles('yarn.lock') }}
28
+ key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }}
29
29
  - name: Install Node modules with Yarn for renderer package
30
30
  run: |
31
31
  yarn install --no-progress --no-emoji
@@ -8,7 +8,7 @@ jobs:
8
8
  matrix:
9
9
  ruby: [2.7]
10
10
  node: [14]
11
- runs-on: ubuntu-latest
11
+ runs-on: ubuntu-22.04
12
12
  steps:
13
13
  - uses: actions/checkout@v2
14
14
  - name: Setup Ruby
@@ -28,7 +28,7 @@ jobs:
28
28
  uses: actions/cache@v2
29
29
  with:
30
30
  path: vendor/bundle
31
- key: v4-package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}
31
+ key: v5-package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}
32
32
  - name: Install Ruby Gems for package
33
33
  run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
34
34
  - name: Run rspec tests
data/.rubocop.yml CHANGED
@@ -94,6 +94,8 @@ RSpec/AnyInstance:
94
94
  Exclude:
95
95
  - 'spec/react_on_rails/git_utils_spec.rb'
96
96
  - 'spec/react_on_rails/locales_to_js_spec.rb'
97
+ - 'spec/react_on_rails/binstubs/dev_spec.rb'
98
+ - 'spec/react_on_rails/binstubs/dev_static_spec.rb'
97
99
 
98
100
  RSpec/DescribeClass:
99
101
  Enabled: false
@@ -111,6 +113,8 @@ RSpec/BeforeAfterAll:
111
113
  Exclude:
112
114
  - 'spec/react_on_rails/generators/dev_tests_generator_spec.rb'
113
115
  - 'spec/react_on_rails/generators/install_generator_spec.rb'
116
+ - 'spec/react_on_rails/binstubs/dev_spec.rb'
117
+ - 'spec/react_on_rails/binstubs/dev_static_spec.rb'
114
118
 
115
119
  RSpec/MessageChain:
116
120
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -17,6 +17,24 @@ 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
+ ### [13.3.0] - 2022-01-29
21
+ ### Fixed
22
+ - Fixed pack not found warning while using `react_component` and `react_component_hash` helpers, even when corresponding chunks are present. [PR 1511](https://github.com/shakacode/react_on_rails/pull/1511) by [pulkitkkr](https://github.com/pulkitkkr)
23
+ - Fixed FS-based packs generation functionality to trigger pack generation on the creation of a new react component inside `components_subdirectory`. [PR 1506](https://github.com/shakacode/react_on_rails/pull/1506) by [pulkitkkr](https://github.com/pulkitkkr)
24
+ - Upgrade several JS dependencies to fix security issues. [PR 1514](https://github.com/shakacode/react_on_rails/pull/1514) by [ahangarha](https://github.com/ahangarha)
25
+
26
+ ### Added
27
+ - Added `./bin/dev` and `./bin/dev-static` executables to ease and standardize running the dev server. [PR 1491](https://github.com/shakacode/react_on_rails/pull/1491) by [ahangarha](https://github.com/ahangarha)
28
+
29
+ ### [13.2.0] - 2022-12-23
30
+
31
+ ### Fixed
32
+ - Fix reactOnRailsPageUnloaded when there is no component on the page. Important for apps using both hotwire and react_on_rails. [PR 1498](https://github.com/shakacode/react_on_rails/pull/1498) by [NhanHo](https://github.com/NhanHo).
33
+ - Fixing wrong type. The throwIfMissing param of getStore should be optional as it defaults to true. [PR 1480](https://github.com/shakacode/react_on_rails/pull/1480) by [wouldntsavezion](https://github.com/wouldntsavezion).
34
+
35
+ ### Added
36
+ - Exposed `reactHydrateOrRender` utility via [PR 1481](https://github.com/shakacode/react_on_rails/pull/1481) by [vaukalak](https://github.com/vaukalak).
37
+
20
38
  ### [13.1.0] - 2022-08-20
21
39
 
22
40
  #### Improved
@@ -1042,7 +1060,9 @@ Best done with Object destructing:
1042
1060
  ##### Fixed
1043
1061
  - Fix several generator related issues.
1044
1062
 
1045
- [Unreleased]: https://github.com/shakacode/react_on_rails/compare/13.0.2...master
1063
+ [Unreleased]: https://github.com/shakacode/react_on_rails/compare/13.3.0...master
1064
+ [13.3.0]: https://github.com/shakacode/react_on_rails/compare/13.2.0...13.3.0
1065
+ [13.2.0]: https://github.com/shakacode/react_on_rails/compare/13.1.0...13.2.0
1046
1066
  [13.1.0]: https://github.com/shakacode/react_on_rails/compare/13.0.2...13.1.0
1047
1067
  [13.0.2]: https://github.com/shakacode/react_on_rails/compare/13.0.1...13.0.2
1048
1068
  [13.0.1]: https://github.com/shakacode/react_on_rails/compare/13.0.0...13.0.1
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- gem "shakapacker", ">= 6.4.0"
3
+ gem "shakapacker", "6.5.1"
4
4
  gem "bootsnap", require: false
5
5
  gem "rails", "~> 7.0"
6
6
  gem "sqlite3"
7
7
  gem "sass-rails", "~> 6.0"
8
8
  gem "uglifier"
9
9
  gem "jquery-rails"
10
- gem "puma"
10
+ gem "puma", "~> 5.0"
11
11
 
12
12
  # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
13
13
  gem "turbolinks" if ENV["DISABLE_TURBOLINKS"].nil? || ENV["DISABLE_TURBOLINKS"].strip.empty?
data/README.md CHANGED
@@ -48,6 +48,8 @@ To provide a high performance framework for integrating Ruby on Rails with React
48
48
 
49
49
  Given that `rails/webpacker` gem already provides basic React integration, why would you use "React on Rails"?
50
50
 
51
+ 1. Automatic configuration of what bundles are added to the page based on what React components are on the page. This results in faster browser loading time via smaller bundle sizes.
52
+ 1. Keep up with the latest changes of different versions of React. React 18 is supported.
51
53
  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.
52
54
  Tight integration with [shakapacker](https://github.com/shakacode/shakapacker) (or it's predecessor [rails/webpacker](https://github.com/rails/webpacker)).
53
55
  1. Server-Side Rendering (SSR), often used for SEO crawler indexing and UX performance.
@@ -96,6 +98,11 @@ The gem is available as open source under the terms of the [MIT License](https:/
96
98
 
97
99
  # Supporters
98
100
 
101
+ The following companies support our open source projects, and ShakaCode uses their products!
102
+
103
+ <br />
104
+ <br />
105
+
99
106
  <a href="https://www.jetbrains.com">
100
107
  <img src="https://user-images.githubusercontent.com/4244251/184881139-42e4076b-024b-4b30-8c60-c3cd0e758c0a.png" alt="JetBrains" height="120px">
101
108
  </a>
@@ -120,8 +127,3 @@ The gem is available as open source under the terms of the [MIT License](https:/
120
127
  <a href="https://www.honeybadger.io">
121
128
  <img src="https://user-images.githubusercontent.com/4244251/184881133-79ee9c3c-8165-4852-958e-31687b9536f4.png" alt="Honeybadger" height="55px">
122
129
  </a>
123
-
124
- <br />
125
- <br />
126
-
127
- The following companies support our open source projects, and ShakaCode uses their products!
@@ -58,6 +58,15 @@ The best source of docs is the main [ReactOnRails.js](https://github.com/shakaco
58
58
  */
59
59
  getStore(name, throwIfMissing = true )
60
60
 
61
+ /**
62
+ * Renders or hydrates the react element passed. In case react version is >=18 will use the new api.
63
+ * @param domNode
64
+ * @param reactElement
65
+ * @param hydrate if true will perform hydration, if false will render
66
+ * @returns {Root|ReactComponent|ReactElement|null}
67
+ */
68
+ reactHydrateOrRender(domNode, reactElement, hydrate)
69
+
61
70
  /**
62
71
  * Set options for ReactOnRails, typically before you call ReactOnRails.register
63
72
  * Available Options:
@@ -9,15 +9,25 @@ Note, the best way to understand how to use ReactOnRails is to study a few simpl
9
9
 
10
10
  ## Basic Installation
11
11
 
12
- *See also [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/guides/installation-into-an-existing-rails-app/).*
12
+ These steps assume that you've got a rails application with webpacker (e.g. one
13
+ generated using `rails new my_app --javascript=webpack`). If your
14
+ application is not yet set up to use webpacker, please see
15
+ [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/guides/installation-into-an-existing-rails-app/).*
13
16
 
14
- 1. Add the `react_on_rails` gem to Gemfile:
17
+ 1. Add the `shakapacker` and `react_on_rails` gem to Gemfile:
15
18
 
16
19
  ```bash
20
+ bundle add shakapacker --strict
17
21
  bundle add react_on_rails --strict
18
22
  ```
19
23
 
20
- 2. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`).
24
+ 2. Run installation command for webpacker:
25
+
26
+ ```bash
27
+ rails webpacker:install
28
+ ```
29
+
30
+ 3. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`).
21
31
 
22
32
  3. Run the generator:
23
33
 
@@ -27,9 +37,8 @@ Note, the best way to understand how to use ReactOnRails is to study a few simpl
27
37
 
28
38
  4. Start the app:
29
39
 
30
- ```bash
31
- rails s
32
- ```
40
+ - Run `./bin/dev` for HMR
41
+ - Run `./bin/dev-static` for statically created bundles (no HMR)
33
42
 
34
43
  5. Visit http://localhost:3000/hello_world.
35
44
 
@@ -47,6 +47,11 @@ for all client files, including your sources and node_modules.
47
47
  # NOTE: you typically will leave the commented out configurations set to their defaults.
48
48
  # Thus, you only need to pay careful attention to the non-commented settings in this file.
49
49
  ReactOnRails.configure do |config|
50
+ # You can optionally add values to your rails_context. This object is passed
51
+ # every time a component renders.
52
+ # See below for an example definition of RenderingExtension
53
+ config.rendering_extension = RenderingExtension
54
+
50
55
  # `trace`: General debugging flag.
51
56
  # The default is true for development, off otherwise.
52
57
  # With true, you get detailed logs of rendering and stack traces if you call setTimout,
@@ -74,6 +79,10 @@ ReactOnRails.configure do |config|
74
79
  # In this example, the module BuildProductionCommand would have a class method `call`.
75
80
  config.build_production_command = "RAILS_ENV=production bin/webpacker"
76
81
 
82
+ # NOTE:
83
+ # When specifying `build_production_command`, you need to disable `rails/webpacker`
84
+ # configuration by setting `webpacker_precompile: false` in your `config/webpacker.yml` file.
85
+
77
86
  # See bottom for an example of the BuildProductionCommand module.
78
87
  # config.build_production_command = BuildProductionCommand
79
88
  # If you wish to utilize ReactOnRailsPro production bundle caching logic, then use
@@ -95,6 +104,11 @@ ReactOnRails.configure do |config|
95
104
  # If you are hashing this file (supposing you are using the same file for client rendering), then
96
105
  # you should include a name that matches your bundle name in your webpack config.
97
106
  config.server_bundle_js_file = "server-bundle.js"
107
+
108
+ # `prerender` means server-side rendering
109
+ # default is false. This is an option for view helpers `render_component` and `render_component_hash`.
110
+ # Set to true to change the default value to true.
111
+ config.prerender = false
98
112
 
99
113
  # THE BELOW OPTIONS FOR SERVER-SIDE RENDERING RARELY NEED CHANGING
100
114
  #
@@ -154,14 +168,19 @@ ReactOnRails.configure do |config|
154
168
  ################################################################################
155
169
  ################################################################################
156
170
  # FILE SYSTEM BASED COMPONENT REGISTRY
171
+ # `render_component` and `render_component_hash` view helper methods can
172
+ # auto-load the bundle for the generated component, to avoid having to specify the
173
+ # bundle manually for each view with the component.
157
174
  ################################################################################
158
175
  # components_subdirectory is the name of the subdirectory matched to detect and register components automatically
159
176
  # 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
177
+ config.components_subdirectory = nil
178
+ # Change to a value like this example to enable this feature
179
+ # config.components_subdirectory = "ror_components"
180
+
181
+ # Default configuration to auto loading bundles for components.
182
+ # default is false. The default can be overrident as an option in calls to view helpers
183
+ # `render_component` and `render_component_hash`. You may set to true to change the default to auto loading.
165
184
  config.auto_load_bundle = false
166
185
 
167
186
  ################################################################################
@@ -184,20 +203,6 @@ ReactOnRails.configure do |config|
184
203
  # The default format is json
185
204
  config.i18n_output_format = 'json'
186
205
 
187
- ################################################################################
188
- ################################################################################
189
- # CLIENT RENDERING OPTIONS
190
- # Below options can be overridden by passing options to the react_on_rails
191
- # `render_component` view helper method.
192
- ################################################################################
193
- # default is false
194
- config.prerender = false
195
-
196
- # You can optionally add values to your rails_context. This object is passed
197
- # every time a component renders.
198
- # See below for an example definition of RenderingExtension
199
- config.rendering_extension = RenderingExtension
200
-
201
206
  ################################################################################
202
207
  ################################################################################
203
208
  # TEST CONFIGURATION OPTIONS
@@ -226,7 +231,7 @@ ReactOnRails.configure do |config|
226
231
  #
227
232
  # Define the files we need to check for webpack compilation when running tests.
228
233
  # The default is `%w( manifest.json )` as will be sufficient for most webpacker builds.
229
- # However, if you are generated a server bundle that is NOT hashed (present in manifest.json),
234
+ # However, if you are generating a server bundle that is NOT hashed (present in manifest.json),
230
235
  # then include the file in this list like this:
231
236
  config.webpack_generated_files = %w( server-bundle.js manifest.json )
232
237
  # Note, be sure NOT to include your server-bundle.js if it is hashed, or else React on Rails will
@@ -5,7 +5,8 @@ To use the automated bundle generation feature introduced in React on Rails v13.
5
5
  ## Configuration
6
6
 
7
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.
8
+ To use the automated bundle generation feature, set `nested_entries: true` in the `webpacker.yml` file like this.
9
+ The generated files will go in a nested directory.
9
10
 
10
11
  ```yml
11
12
  default:
@@ -36,7 +37,7 @@ config.auto_load_bundle = true
36
37
  ```
37
38
 
38
39
  ### 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
+ 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
 
41
42
  ```gitignore
42
43
  # Generated React on Rails packs
@@ -55,11 +56,11 @@ If the `webpacker.yml` file is configured as instructed [here](https://github.co
55
56
  ```yml
56
57
  default: &default
57
58
  source_path: app/javascript
58
- source_entry_path: packs
59
+ source_entry_path: packs
59
60
  public_root_path: public
60
61
  public_output_path: packs
61
62
  nested_entries: true
62
- # And more
63
+ # And more
63
64
  ```
64
65
 
65
66
  the directory structure will look like this
@@ -100,7 +101,7 @@ Your layout would contain:
100
101
  ```
101
102
 
102
103
 
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
+ 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
  ```
105
106
  app/javascript:
106
107
  └── packs: # sets up webpack entries
@@ -138,8 +139,8 @@ Your layout would now contain:
138
139
 
139
140
  ```
140
141
  app/javascript:
141
- └── packs
142
- └── src:
142
+ └── packs
143
+ └── src:
143
144
  │ └── Foo
144
145
  │ │ └── ...
145
146
  │ │ └── ror_components # configured as `components_subdirectory`
@@ -148,25 +149,25 @@ app/javascript:
148
149
  │ │ └── ...
149
150
  │ │ └── ror_components # configured as `components_subdirectory`
150
151
  │ │ │ └── BarComponentOne.jsx
151
- │ │ │ └── BarComponentTwo.jsx
152
+ │ │ │ └── BarComponentTwo.jsx
152
153
  ```
153
154
 
154
155
  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
 
156
157
  ```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) %>
158
+ <%= react_component("FooComponentOne", {}, auto_load_bundle: true) %>
159
+ <%= react_component("BarComponentOne", {}, auto_load_bundle: true) %>
160
+ <%= react_component("BarComponentTwo", {}, auto_load_bundle: true) %>
160
161
  ```
161
162
 
162
163
  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
 
164
165
  ```erb
165
- <% foo_component_one_data = react_component_hash("FooComponentOne",
166
+ <% foo_component_one_data = react_component_hash("FooComponentOne",
166
167
  prerender: true,
167
168
  auto_load_bundle: true
168
169
  props: {}
169
- ) %>
170
+ ) %>
170
171
  <% content_for :title do %>
171
172
  <%= foo_component_one_data['title'] %>
172
173
  <% end %>
@@ -179,6 +180,8 @@ The default value of the `auto_load_bundle` parameter can be specified by settin
179
180
 
180
181
  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
 
183
+ Once generated, all server entrypoints will be imported into a file named `[ReactOnRails.configuration.server_bundle_js_file]-generated.js`, which in turn will be imported into a source file named the same as `ReactOnRails.configuration.server_bundle_js_file`. If your server bundling logic is such that your server bundle source entrypoint is not named the same as your `ReactOnRails.configuration.server_bundle_js_file` & changing it would be difficult, please let us know.
184
+
182
185
  *Note: If specifying separate definitions for client and server rendering, please make sure to delete the generalized `ComponentName.jsx` file.*
183
186
 
184
187
  ### Using Automated Bundle Generation Feature with already defined packs
@@ -7,48 +7,46 @@
7
7
  1. Add the following to your Gemfile and `bundle install`. We recommend fixing the version of React on Rails, as you will need to keep the exact version in sync with the version in your `package.json` file.
8
8
 
9
9
  ```ruby
10
- gem "react_on_rails", "12.0.0" # Update to the current version
11
- gem "webpacker", "~> 5"
10
+ gem "react_on_rails", "13.1.0" # Use the latest and the exact version
11
+ gem "shakapacker", "6.5.4"
12
12
  ```
13
13
 
14
- 1. Add the webpacker and react_on_rails gems
15
- _Use the latest version for react_on_rails._
14
+ Or use `bundle add`:
16
15
 
17
- ```
18
- bundle add webpacker
19
- bundle add react_on_rails --version=12.0.4 --strict
20
- ```
16
+ ```bash
17
+ bundle add react_on_rails --version=13.1.0 --strict
18
+ bundle add shakapacker --strict
19
+ ```
21
20
 
22
21
  2. Run the following 2 commands to install Webpacker with React. Note, if you are using an older version of Rails than 5.1, you'll need to install webpacker with React per the instructions [here](https://github.com/rails/webpacker).
23
22
 
24
23
  ```bash
25
- bundle exec rails webpacker:install
26
- bundle exec rails webpacker:install:react
24
+ rails webpacker:install
27
25
  ```
28
26
 
29
27
  3. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`).
30
28
 
31
- 4. See help for the generator:
29
+ 4. Run the generator with a simple "Hello World" example (more options below):
32
30
 
33
31
  ```bash
34
- $ rails generate react_on_rails:install --help
32
+ rails generate react_on_rails:install
35
33
  ```
36
34
 
37
- 5. Run the generator with a simple "Hello World" example (more options below):
35
+ For more information about this generator use `--help` option:
38
36
 
39
37
  ```bash
40
- $ rails generate react_on_rails:install
38
+ rails generate react_on_rails:install --help
41
39
  ```
40
+ 5. Ensure that you have `overmind` or `foreman` installed
42
41
 
43
- 6. Ensure that you have `foreman` installed: `gem install foreman`.
44
-
45
- 7. Start your Rails server:
42
+ 6. Start your Rails server:
46
43
 
47
44
  ```bash
48
- $ foreman start -f Procfile.dev
45
+ ./bin/dev
49
46
  ```
47
+ Note: `foreman` defaults to PORT 5000 unless you set the value of PORT in your environment. For example, you can `export PORT=3000` to use the Rails default port of 3000. For the hello_world example this is already set.
50
48
 
51
- 8. Visit [localhost:3000/hello_world](http://localhost:3000/hello_world). Note: `foreman` defaults to PORT 5000 unless you set the value of PORT in your environment. For example, you can `export PORT=3000` to use the Rails default port of 3000. For the hello_world example this is already set.
49
+ 7. Visit [localhost:3000/hello_world](http://localhost:3000/hello_world).
52
50
 
53
51
  ## Installation
54
52
 
@@ -60,7 +58,7 @@ See the [Installation Overview](https://www.shakacode.com/react-on-rails/docs/ad
60
58
  All JavaScript in React On Rails is loaded from npm: [react-on-rails](https://www.npmjs.com/package/react-on-rails). To manually install this (you did not use the generator), assuming you have a standard configuration, run this command (assuming you are in the directory where you have your `node_modules`):
61
59
 
62
60
  ```bash
63
- $ yarn add react-on-rails --exact
61
+ yarn add react-on-rails --exact
64
62
  ```
65
63
 
66
64
  That will install the latest version and update your package.json. **NOTE:** the `--exact` flag will ensure that you do not have a "~" or "^" for your react-on-rails version in your package.json.