react_on_rails 13.3.2 → 13.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37f8e087fd09c6ea86239307c6c47121d294d73c84065b07ff0756e79ed6b679
4
- data.tar.gz: 93fc7de963700c87af99cdb13ba4511c6b305721d1f2c784d4cd840f6084775a
3
+ metadata.gz: 0b5950d1de16d2db5f3944bb18bb65155f038f5587e8856e8c6418bc59cbcca9
4
+ data.tar.gz: d40aa0a760a7ef09df3a7b6550e1d1619001183895c28293bd3f993cb08e16c2
5
5
  SHA512:
6
- metadata.gz: 2c7fa29cd46918b4605e8d9f5481eec8506536bd096cfbeb90bc284e0b246322a16956d0e218c9d7e905a5638674863df222b781826f47b1eafeb79e11ec03c5
7
- data.tar.gz: 481709881b0f9d24fb5047b213325c189185e9869e62f664afb8dbcea6b3a24b510f12ba17e1ffc0b7db4c7e478318c92fc93e8d7188b255b26cc245ac430011
6
+ metadata.gz: 324d1e13a73437cdcd302961ae9d4a91303bdb2872e8355b9d4677d6ff9a92aa77e98df0ff21934782ae39e4bf540e39c37aca38337385d85aaeef72cbab37cd
7
+ data.tar.gz: f762b29b6619e39067573317c027b9aa7a390a6d2d86b78f73a039ad3c1c1e26c6985ec8df3c3e00c10d0ed179f4246415cb573efc77d0f2d619737e643e54cb
data/.circleci/config.yml CHANGED
@@ -1,3 +1,4 @@
1
+ # CircleCI is not longer in use by this repository & this file is now for reference only.
1
2
  version: 2
2
3
 
3
4
  aliases:
@@ -53,7 +54,7 @@ aliases:
53
54
  - &install-dummy-app-ruby-gems
54
55
  name: Install Ruby Gems for dummy app
55
56
  command: |
56
- gem install bundler
57
+ gem install bundler:2.4.9
57
58
  echo "Bundler version: "; bundle --version
58
59
  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
60
 
@@ -61,7 +62,7 @@ aliases:
61
62
  - &install-package-ruby-gems
62
63
  name: Install Ruby Gems for package
63
64
  command: |
64
- gem install bundler
65
+ gem install bundler:2.4.9
65
66
  echo "Bundler version: "; bundle --version
66
67
  bundle lock --add-platform 'x86_64-linux'
67
68
  bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
@@ -272,12 +273,12 @@ jobs:
272
273
  name: Prep for CI
273
274
  # TODO -- need to leverage Circle CI containers
274
275
  command: |
275
- bundle exec rails prepare_for_ci
276
+ bundle exec rake prepare_for_ci
276
277
  - run:
277
278
  name: Main CI
278
279
  # TODO -- need to leverage Circle CI containers
279
280
  command: |
280
- bundle exec rails run_rspec:all_dummy
281
+ bundle exec rake run_rspec:all_dummy
281
282
  # The following step will run only if the main job is finished successfully.
282
283
  # Build hook is triggered by curl command described here https://docs.netlify.com/configure-builds/build-hooks/
283
284
  # NETLIFY_HOOK is an environment variable on CircleCI to keep sensitive data outside the repo
@@ -0,0 +1,19 @@
1
+ ### Summary
2
+
3
+ _Remove this paragraph and provide a general description of the code changes in your pull
4
+ request... were there any bugs you had fixed? If so, mention them. If
5
+ these bugs have open GitHub issues, be sure to tag them here as well,
6
+ to keep the conversation linked together._
7
+
8
+ ### Pull Request checklist
9
+ _Remove this line after checking all the items here. If the item is not applicable to the PR, both check it out and wrap it by `~`._
10
+
11
+ - [ ] Add/update test to cover these changes
12
+ - [ ] Update documentation
13
+ - [ ] Update CHANGELOG file
14
+ _Add the CHANGELOG entry at the top of the file._
15
+
16
+ ### Other Information
17
+
18
+ _Remove this paragraph and mention any other important and relevant information such as benchmarks._
19
+
@@ -15,6 +15,7 @@ jobs:
15
15
  uses: ruby/setup-ruby@v1
16
16
  with:
17
17
  ruby-version: ${{ matrix.ruby }}
18
+ bundler: 2.4.9
18
19
  - name: Setup Node
19
20
  uses: actions/setup-node@v2-beta
20
21
  with:
@@ -44,7 +45,7 @@ jobs:
44
45
  yarn run eslint -v
45
46
  sudo yarn global add yalc
46
47
  - name: Install Ruby Gems for package
47
- run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
48
+ run: bundle check --path=vendor/bundle || bundle _2.4.9_ install --path=vendor/bundle --jobs=4 --retry=3
48
49
  - name: Linting of Ruby
49
50
  run: bundle exec rubocop
50
51
  - name: Linting of JS
@@ -1,6 +1,6 @@
1
1
  name: Main test
2
2
 
3
- on: [push, pull_request]
3
+ on: [push]
4
4
 
5
5
  jobs:
6
6
  build-dummy-app-webpack-test-bundles:
@@ -15,6 +15,7 @@ jobs:
15
15
  uses: ruby/setup-ruby@v1
16
16
  with:
17
17
  ruby-version: ${{ matrix.ruby }}
18
+ bundler: 2.4.9
18
19
  # libyaml-dev is needed for psych v5
19
20
  # this gem depends on sdoc which depends on rdoc which depends on psych
20
21
  - name: Fix dependency for libyaml-dev
@@ -33,7 +34,7 @@ jobs:
33
34
  echo "Yarn version: "; yarn --version
34
35
  echo "Bundler version: "; bundle --version
35
36
  - name: Save root node_modules to cache
36
- uses: actions/cache@v2
37
+ uses: actions/cache@v3
37
38
  with:
38
39
  path: node_modules
39
40
  key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }}
@@ -45,7 +46,7 @@ jobs:
45
46
  - name: yalc publish for react-on-rails
46
47
  run: yalc publish
47
48
  - name: Save spec/dummy/node_modules to cache
48
- uses: actions/cache@v2
49
+ uses: actions/cache@v3
49
50
  with:
50
51
  path: spec/dummy/node_modules
51
52
  key: v5-dummy-app-node-modules-cache-${{ hashFiles('spec/dummy/yarn.lock') }}
@@ -54,12 +55,12 @@ jobs:
54
55
  - name: Install Node modules with Yarn for dummy app
55
56
  run: cd spec/dummy && yarn install --no-progress --no-emoji
56
57
  - name: Save dummy app ruby gems to cache
57
- uses: actions/cache@v2
58
+ uses: actions/cache@v3
58
59
  with:
59
60
  path: spec/dummy/vendor/bundle
60
61
  key: v5-dummy-app-gem-cache-${{ hashFiles('spec/dummy/Gemfile.lock') }}
61
62
  - name: Install Ruby Gems for dummy app
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
+ run: cd spec/dummy && bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle _2.4.9_ install --path=vendor/bundle --jobs=4 --retry=3
63
64
  - name: generate file system-based packs
64
65
  run: cd spec/dummy && RAILS_ENV=test bundle exec rake react_on_rails:generate_packs
65
66
  - name: Build test bundles for dummy app
@@ -67,7 +68,7 @@ jobs:
67
68
  - id: get-sha
68
69
  run: echo "::set-output name=sha::$(git rev-parse HEAD)"
69
70
  - name: Save test webpack bundles to cache (for build number checksum used by rspec job)
70
- uses: actions/cache@v2
71
+ uses: actions/cache/save@v3
71
72
  with:
72
73
  path: spec/dummy/public/webpack
73
74
  key: v5-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }}
@@ -78,7 +79,7 @@ jobs:
78
79
  matrix:
79
80
  ruby: [2.7]
80
81
  node: [14]
81
- rake_task: ['run_rspec:all_dummy', 'run_rspec:all_but_examples', 'run_rspec:examples']
82
+ rake_task: ['run_rspec:all_but_examples', 'run_rspec:examples']
82
83
  runs-on: ubuntu-22.04
83
84
  steps:
84
85
  - uses: actions/checkout@v2
@@ -86,6 +87,7 @@ jobs:
86
87
  uses: ruby/setup-ruby@v1
87
88
  with:
88
89
  ruby-version: ${{ matrix.ruby }}
90
+ bundler: 2.4.9
89
91
  - name: Setup Node
90
92
  uses: actions/setup-node@v2-beta
91
93
  with:
@@ -100,33 +102,32 @@ jobs:
100
102
  echo "Yarn version: "; yarn --version
101
103
  echo "Bundler version: "; bundle --version
102
104
  - name: Save root node_modules to cache
103
- uses: actions/cache@v2
105
+ uses: actions/cache@v3
104
106
  with:
105
107
  path: node_modules
106
108
  key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }}
107
109
  - name: Save root ruby gems to cache
108
- uses: actions/cache@v2
110
+ uses: actions/cache@v3
109
111
  with:
110
112
  path: vendor/bundle
111
113
  key: v5-package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}
112
114
  - name: Save dummy app ruby gems to cache
113
- uses: actions/cache@v2
115
+ uses: actions/cache@v3
114
116
  with:
115
117
  path: spec/dummy/vendor/bundle
116
118
  key: v5-dummy-app-gem-cache-${{ hashFiles('spec/dummy/Gemfile.lock') }}
117
119
  - name: Save spec/dummy/node_modules to cache
118
- uses: actions/cache@v2
120
+ uses: actions/cache@v3
119
121
  with:
120
122
  path: spec/dummy/node_modules
121
123
  key: v5-dummy-app-node-modules-cache-${{ hashFiles('spec/dummy/yarn.lock') }}
122
124
  - id: get-sha
123
125
  run: echo "::set-output name=sha::$(git rev-parse HEAD)"
124
126
  - name: Save test webpack bundles to cache (for build number checksum used by rspec job)
125
- uses: actions/cache@v2
127
+ uses: actions/cache@v3
126
128
  with:
127
129
  path: spec/dummy/public/webpack
128
130
  key: v5-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }}
129
-
130
131
  - name: Install Node modules with Yarn for renderer package
131
132
  run: |
132
133
  yarn install --no-progress --no-emoji
@@ -139,7 +140,7 @@ jobs:
139
140
  - name: Install Ruby Gems for package
140
141
  run: bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
141
142
  - name: Install Ruby Gems for dummy app
142
- 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
143
+ run: cd spec/dummy && bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle _2.4.9_ install --path=vendor/bundle --jobs=4 --retry=3
143
144
  - name: Ensure minimum required Chrome version
144
145
  run: |
145
146
  echo -e "Already installed $(google-chrome --version)\n"
@@ -152,16 +153,14 @@ jobs:
152
153
  sudo apt-get install google-chrome-stable
153
154
  echo -e "\nInstalled $(google-chrome --version)"
154
155
  fi
155
- - name: Touch webpack bundles
156
- run: touch spec/dummy/public/webpack/test/*
157
156
  - name: Install yalc globally
158
157
  run: sudo yarn global add yalc
159
158
  - name: Increase the amount of inotify watchers
160
159
  run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
161
- - name: Prep for CI
162
- run: bundle exec rails prepare_for_ci
160
+ - name: generate file system-based packs
161
+ run: cd spec/dummy && RAILS_ENV=test bundle exec rake react_on_rails:generate_packs
163
162
  - name: Main CI
164
- run: bundle exec rails ${{ matrix.rake_task }}
163
+ run: bundle exec rake ${{ matrix.rake_task }}
165
164
  - name: Store test results
166
165
  uses: actions/upload-artifact@v2
167
166
  with:
@@ -15,6 +15,7 @@ jobs:
15
15
  uses: ruby/setup-ruby@v1
16
16
  with:
17
17
  ruby-version: ${{ matrix.ruby }}
18
+ bundler: 2.4.9
18
19
  - name: Print system information
19
20
  run: |
20
21
  echo "Linux release: "; cat /etc/issue
data/.prettierignore CHANGED
@@ -3,10 +3,12 @@ package.json
3
3
  tmp/
4
4
  coverage/
5
5
  **/app/assets/webpack/
6
- spec/dummy/public
7
6
  gen-examples/examples/*
8
7
  node_package/lib/*
9
8
  spec/react_on_rails/dummy-for-generators/app/javascript/bundles/HelloWorld/*
10
9
  bundle/
11
10
  spec/dummy/lib/bs/**
11
+ spec/dummy/public
12
+ **/.yalc/**
13
+ **/generated/**
12
14
  *.bs.js
data/CHANGELOG.md CHANGED
@@ -17,6 +17,19 @@ 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.4] - 2022-05-23
21
+
22
+ ### Added
23
+ - Improved functionality of Filesystem-based pack generation & auto-bundling. Added `make_generated_server_bundle_the_entrypoint` configuration key. [PR 1531](https://github.com/shakacode/react_on_rails/pull/1531) by [judahmeek](https://github.com/judahmeek)
24
+
25
+ ### Removed
26
+ - Removed unneeded `HMR=true` from `Procfile.dev` in install template [PR 1537](https://github.com/shakacode/react_on_rails/pull/1537) by [ahangarha](https://github.com/ahangarha).
27
+
28
+ ### [13.3.3] - 2022-03-21
29
+
30
+ ### Fixed
31
+ - Fixed bug regarding loading FS-based packs. [PR 1527](https://github.com/shakacode/react_on_rails/pull/1527) by [judahmeek](https://github.com/judahmeek)
32
+
20
33
  ### [13.3.2] - 2022-02-24
21
34
 
22
35
  ### Fixed
@@ -65,7 +78,7 @@ Changes since last non-beta release.
65
78
 
66
79
  - 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).
67
80
 
68
- In exchange, you may see a warning like this when building a Webpack bundle under React 16:
81
+ In exchange, you may see a warning like this when building using any version of React below 18:
69
82
  ```
70
83
  WARNING in ./node_modules/react-on-rails/node_package/lib/reactHydrateOrRender.js19:25-52
71
84
  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'
@@ -1072,7 +1085,9 @@ Best done with Object destructing:
1072
1085
  ##### Fixed
1073
1086
  - Fix several generator related issues.
1074
1087
 
1075
- [Unreleased]: https://github.com/shakacode/react_on_rails/compare/13.3.2...master
1088
+ [Unreleased]: https://github.com/shakacode/react_on_rails/compare/13.3.4...master
1089
+ [13.3.4]: https://github.com/shakacode/react_on_rails/compare/13.3.3...13.3.4
1090
+ [13.3.3]: https://github.com/shakacode/react_on_rails/compare/13.3.2...13.3.3
1076
1091
  [13.3.2]: https://github.com/shakacode/react_on_rails/compare/13.3.1...13.3.2
1077
1092
  [13.3.1]: https://github.com/shakacode/react_on_rails/compare/13.3.0...13.3.1
1078
1093
  [13.3.0]: https://github.com/shakacode/react_on_rails/compare/13.2.0...13.3.0
@@ -8,6 +8,7 @@ gem "sass-rails", "~> 6.0"
8
8
  gem "uglifier"
9
9
  gem "jquery-rails"
10
10
  gem "puma", "~> 5.0"
11
+ gem "bundler", "2.4.9"
11
12
 
12
13
  # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
13
14
  gem "turbolinks" if ENV["DISABLE_TURBOLINKS"].nil? || ENV["DISABLE_TURBOLINKS"].strip.empty?
@@ -29,8 +30,8 @@ group :development, :test do
29
30
  gem "pry-rails"
30
31
  gem "pry-rescue"
31
32
  gem "rubocop", "1.14.0", require: false
32
- gem "rubocop-performance", "1.16.0", require: false
33
- gem "rubocop-rspec", "2.4.0", require: false
33
+ gem "rubocop-performance", require: false
34
+ gem "rubocop-rspec", require: false
34
35
  gem "scss_lint", require: false
35
36
  gem "spring", "~> 4.0"
36
37
  end
@@ -46,5 +47,5 @@ group :test do
46
47
  gem "rspec-rails"
47
48
  gem "rspec-retry"
48
49
  gem "selenium-webdriver"
49
- gem "webdrivers", "3.9.4"
50
+ gem "webdrivers"
50
51
  end
data/README.md CHANGED
@@ -53,7 +53,7 @@ Given that `rails/webpacker` gem already provides basic React integration, why w
53
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.
54
54
  Tight integration with [shakapacker](https://github.com/shakacode/shakapacker) (or it's predecessor [rails/webpacker](https://github.com/rails/webpacker)).
55
55
  1. Server-Side Rendering (SSR), often used for SEO crawler indexing and UX performance.
56
- 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)
56
+ 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/)
57
57
  1. [Redux](https://github.com/reactjs/redux) and [React Router](https://github.com/ReactTraining/react-router#readme) integration with server-side-rendering.
58
58
  1. [Internationalization (I18n) and (localization)](https://www.shakacode.com/react-on-rails/docs/guides/i18n)
59
59
  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/).
@@ -127,3 +127,6 @@ The following companies support our open source projects, and ShakaCode uses the
127
127
  <a href="https://www.honeybadger.io">
128
128
  <img src="https://user-images.githubusercontent.com/4244251/184881133-79ee9c3c-8165-4852-958e-31687b9536f4.png" alt="Honeybadger" height="55px">
129
129
  </a>
130
+ <a href="https://reviewable.io">
131
+ <img src="https://user-images.githubusercontent.com/20628911/230848305-c94510a4-82d7-468f-bf9f-eeb81d3f2ce0.png" alt="Reviewable" height="55px">
132
+ </a>
@@ -178,11 +178,21 @@ ReactOnRails.configure do |config|
178
178
  # Change to a value like this example to enable this feature
179
179
  # config.components_subdirectory = "ror_components"
180
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
181
+ # Default is false.
182
+ # The default can be overidden as an option in calls to view helpers
183
183
  # `render_component` and `render_component_hash`. You may set to true to change the default to auto loading.
184
184
  config.auto_load_bundle = false
185
185
 
186
+ # Default is false
187
+ # Set this to true & instead of trying to import the generated server components into your existing
188
+ # server bundle entrypoint, the PacksGenerator will create a server bundle entrypoint using
189
+ # config.server_bundle_js_file for the filename.
190
+ config.make_generated_server_bundle_the_entrypoint = false
191
+
192
+ # Default is true, which matches Webpacker/Shakapacker's defer default for `append_javascript_pack`
193
+ # Set this to false to have `defer: false` added to your `append_javascript_pack` calls for generated entrypoints.
194
+ config.defer_generated_component_packs = true
195
+
186
196
  ################################################################################
187
197
  # I18N OPTIONS
188
198
  ################################################################################
@@ -101,7 +101,7 @@ Your layout would contain:
101
101
  <%= stylesheet_pack_tag 'application' %>
102
102
  ```
103
103
 
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
+ Now 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.
105
105
 
106
106
  ```
107
107
  app/javascript:
@@ -124,23 +124,26 @@ The tricky part is to figure out which bundles to load on any Rails view. [Shaka
124
124
 
125
125
  #### Solution
126
126
 
127
- 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:
127
+ File-system-based automated pack generation simplifies this process with a new option for the view helpers.
128
128
 
129
- 1. Remove parameters passed directly to `javascript_pack_tag` and `stylesheet_pack_tag`.
130
- 2. Remove parameters passed directly to `append_javascript_pack_tag` and `append_stylesheet_pack_tag`.
129
+ For example, if you wanted to utilize our file-system based entrypoint generation for `FooComponentOne` & `BarComponentOne`, but not `BarComponentTwo` (for whatever reason), then...
130
+
131
+ 1. Remove generated entrypoints from parameters passed directly to `javascript_pack_tag` and `stylesheet_pack_tag`.
132
+ 2. Remove generated entrypoints from parameters passed directly to `append_javascript_pack_tag` and `append_stylesheet_pack_tag`.
131
133
 
132
134
  Your layout would now contain:
133
135
 
134
136
  ```erb
135
- <%= javascript_pack_tag %>
136
- <%= stylesheet_pack_tag %>
137
+ <%= javascript_pack_tag('BarComponentTwo') %>
138
+ <%= stylesheet_pack_tag('BarComponentTwo') %>
137
139
  ```
138
140
 
139
- 3. Create a directory structure as mentioned below:
141
+ 3. Create a directory structure where the components that you want to be auto-generated are within `ReactOnRails.configuration.components_subdirectory`, which should be a subdirectory of `Shakapacker.config.source_path`:
140
142
 
141
143
  ```
142
144
  app/javascript:
143
- └── packs
145
+ └── packs:
146
+ │ └── BarComponentTwo.jsx # Internally uses ReactOnRails.register
144
147
  └── src:
145
148
  │ └── Foo
146
149
  │ │ └── ...
@@ -150,18 +153,20 @@ app/javascript:
150
153
  │ │ └── ...
151
154
  │ │ └── ror_components # configured as `components_subdirectory`
152
155
  │ │ │ └── BarComponentOne.jsx
156
+ │ │ └── something_else
153
157
  │ │ │ └── BarComponentTwo.jsx
154
158
  ```
155
159
 
156
- 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:
160
+ 4. You no longer need to register the React components within the `ReactOnRails.configuration.components_subdirectory` nor directly add their bundles. For example you can have a Rails view using three components:
157
161
 
158
162
  ```erb
163
+ <% append_javascript_pack('BarComponentTwo'))>
159
164
  <%= react_component("FooComponentOne", {}, auto_load_bundle: true) %>
160
165
  <%= react_component("BarComponentOne", {}, auto_load_bundle: true) %>
161
- <%= react_component("BarComponentTwo", {}, auto_load_bundle: true) %>
166
+ <%= react_component("BarComponentTwo", {}) %>
162
167
  ```
163
168
 
164
- 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.
169
+ If a component 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.
165
170
 
166
171
  ```erb
167
172
  <% foo_component_one_data = react_component_hash("FooComponentOne",
@@ -185,6 +190,14 @@ Once generated, all server entrypoints will be imported into a file named `[Reac
185
190
 
186
191
  *Note: If specifying separate definitions for client and server rendering, please make sure to delete the generalized `ComponentName.jsx` file.*
187
192
 
193
+ ### Integrating auto-bundling into CI workflows
194
+
195
+ Currently, ReactOnRails contains conditional logic that checks for the existence of generated entrypoint files whenever `react_component` or one of its derivative methods are called. If a generated entrypoint of the same name as provided to `react_component` or `react_component_hash` exists, then an `append_javascript_pack` call is made automatically.
196
+
197
+ This means that `rake react_on_rails:generate_packs` or its programmatic equivalent must be run as a prerequisite to any sort of test or spec that would result in `react_component` or `react_component_hash` being called, even if the generated entrypoint files have already been bundled in a previous workflow/job.
198
+
199
+ Caching of the generated entrypoints between workflow/jobs should also resolve this issue.
200
+
188
201
  ### Using Automated Bundle Generation Feature with already defined packs
189
202
 
190
203
  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.
@@ -56,6 +56,36 @@ document.addEventListener('DOMContentLoaded', () => {
56
56
 
57
57
  ----
58
58
 
59
+ ## Suppress warning related to Can't resolve 'react-dom/client' in React < 18
60
+
61
+ You may see a warning like this when building a Webpack bundle using any version of React below 18:
62
+
63
+ ```
64
+ Module not found: Error: Can't resolve 'react-dom/client' in ....
65
+ ```
66
+
67
+ It can be safely [suppressed](https://webpack.js.org/configuration/other-options/#ignorewarnings) in your Webpack configuration. The following is an example of this suppression in `config/webpack/commonWebpackConfig.js`:
68
+
69
+ ```js
70
+ const { webpackConfig: baseClientWebpackConfig, merge } = require('shakapacker');
71
+
72
+ const commonOptions = {
73
+ resolve: {
74
+ extensions: ['.css', '.ts', '.tsx'],
75
+ },
76
+ };
77
+
78
+ const ignoreWarningsConfig = {
79
+ ignoreWarnings: [/Module not found: Error: Can't resolve 'react-dom\/client'/],
80
+ };
81
+
82
+ const commonWebpackConfig = () => merge({}, baseClientWebpackConfig, commonOptions, ignoreWarningsConfig);
83
+
84
+ module.exports = commonWebpackConfig;
85
+ ```
86
+
87
+ ----
88
+
59
89
  ## HMR and React Hot Reloading
60
90
 
61
91
  Before turning HMR on, consider upgrading to the latest stable gems and packages:
@@ -12,7 +12,7 @@ def run(process)
12
12
  rescue Errno::ENOENT
13
13
  warn <<~MSG
14
14
  ERROR:
15
- Please ensure `Procfile.dev` exist in your project!
15
+ Please ensure `Procfile.dev` exists in your project!
16
16
  MSG
17
17
  exit!
18
18
  end
@@ -12,7 +12,7 @@ def run(process)
12
12
  rescue Errno::ENOENT
13
13
  warn <<~MSG
14
14
  ERROR:
15
- Please ensure `Procfile.dev-static` exist in your project!
15
+ Please ensure `Procfile.dev-static` exists in your project!
16
16
  MSG
17
17
  exit!
18
18
  end
@@ -1,5 +1,5 @@
1
1
  # Procfile for development using HMR
2
2
  # You can run these commands in separate shells
3
3
  rails: bundle exec rails s -p 3000
4
- wp-client: HMR=true bin/webpacker-dev-server
5
- wp-server: HMR=true SERVER_BUNDLE_ONLY=yes bin/webpacker --watch
4
+ wp-client: bin/webpacker-dev-server
5
+ wp-server: SERVER_BUNDLE_ONLY=yes bin/webpacker --watch
@@ -9,10 +9,6 @@ module ReactOnRails
9
9
  end
10
10
 
11
11
  DEFAULT_GENERATED_ASSETS_DIR = File.join(%w[public webpack], Rails.env).freeze
12
- DEFAULT_COMPONENTS_SUBDIRECTORY = nil
13
- DEFAULT_SERVER_RENDER_TIMEOUT = 20
14
- DEFAULT_POOL_SIZE = 1
15
- DEFAULT_RANDOM_DOM_ID = true # for backwards compatability
16
12
 
17
13
  def self.configuration
18
14
  @configuration ||= Configuration.new(
@@ -28,8 +24,8 @@ module ReactOnRails
28
24
  raise_on_prerender_error: Rails.env.development?,
29
25
  trace: Rails.env.development?,
30
26
  development_mode: Rails.env.development?,
31
- server_renderer_pool_size: DEFAULT_POOL_SIZE,
32
- server_renderer_timeout: DEFAULT_SERVER_RENDER_TIMEOUT,
27
+ server_renderer_pool_size: 1,
28
+ server_renderer_timeout: 20,
33
29
  skip_display_none: nil,
34
30
  # skip_display_none is deprecated
35
31
  webpack_generated_files: %w[manifest.json],
@@ -38,35 +34,37 @@ module ReactOnRails
38
34
  server_render_method: nil,
39
35
  build_test_command: "",
40
36
  build_production_command: "",
41
- random_dom_id: DEFAULT_RANDOM_DOM_ID,
37
+ random_dom_id: true,
42
38
  same_bundle_for_client_and_server: false,
43
39
  i18n_output_format: nil,
44
- components_subdirectory: DEFAULT_COMPONENTS_SUBDIRECTORY
40
+ components_subdirectory: nil,
41
+ make_generated_server_bundle_the_entrypoint: false,
42
+ defer_generated_component_packs: true
45
43
  )
46
44
  end
47
45
 
48
46
  class Configuration
49
47
  attr_accessor :node_modules_location, :server_bundle_js_file, :prerender, :replay_console,
50
- :trace, :development_mode,
51
- :logging_on_server, :server_renderer_pool_size,
48
+ :trace, :development_mode, :logging_on_server, :server_renderer_pool_size,
52
49
  :server_renderer_timeout, :skip_display_none, :raise_on_prerender_error,
53
- :generated_assets_dirs, :generated_assets_dir,
50
+ :generated_assets_dirs, :generated_assets_dir, :components_subdirectory,
54
51
  :webpack_generated_files, :rendering_extension, :build_test_command,
55
- :build_production_command,
56
- :i18n_dir, :i18n_yml_dir, :i18n_output_format,
52
+ :build_production_command, :i18n_dir, :i18n_yml_dir, :i18n_output_format,
57
53
  :server_render_method, :random_dom_id, :auto_load_bundle,
58
- :same_bundle_for_client_and_server, :rendering_props_extension, :components_subdirectory
54
+ :same_bundle_for_client_and_server, :rendering_props_extension,
55
+ :make_generated_server_bundle_the_entrypoint,
56
+ :defer_generated_component_packs
59
57
 
60
58
  # rubocop:disable Metrics/AbcSize
61
59
  def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender: nil,
62
- replay_console: nil,
60
+ replay_console: nil, make_generated_server_bundle_the_entrypoint: nil,
63
61
  trace: nil, development_mode: nil,
64
62
  logging_on_server: nil, server_renderer_pool_size: nil,
65
63
  server_renderer_timeout: nil, raise_on_prerender_error: true,
66
64
  skip_display_none: nil, generated_assets_dirs: nil,
67
65
  generated_assets_dir: nil, webpack_generated_files: nil,
68
66
  rendering_extension: nil, build_test_command: nil,
69
- build_production_command: nil,
67
+ build_production_command: nil, defer_generated_component_packs: nil,
70
68
  same_bundle_for_client_and_server: nil,
71
69
  i18n_dir: nil, i18n_yml_dir: nil, i18n_output_format: nil,
72
70
  random_dom_id: nil, server_render_method: nil, rendering_props_extension: nil,
@@ -106,6 +104,8 @@ module ReactOnRails
106
104
  self.server_render_method = server_render_method
107
105
  self.components_subdirectory = components_subdirectory
108
106
  self.auto_load_bundle = auto_load_bundle
107
+ self.make_generated_server_bundle_the_entrypoint = make_generated_server_bundle_the_entrypoint
108
+ self.defer_generated_component_packs = defer_generated_component_packs
109
109
  end
110
110
  # rubocop:enable Metrics/AbcSize
111
111
 
@@ -313,19 +313,12 @@ module ReactOnRails
313
313
  @rails_context.merge(serverSide: server_side)
314
314
  end
315
315
 
316
- def load_pack_for_component(component_name)
317
- is_component_pack_present = File.exist?(generated_components_pack_path(component_name))
318
- is_development = ENV["RAILS_ENV"] == "development"
319
-
320
- if is_development && !is_component_pack_present
321
- ReactOnRails::PacksGenerator.instance.generate_packs_if_stale
322
- raise_missing_pack_error(component_name)
323
- end
324
-
316
+ def load_pack_for_generated_component(component_name)
325
317
  ReactOnRails::WebpackerUtils.raise_nested_entries_disabled unless ReactOnRails::WebpackerUtils.nested_entries?
326
318
 
327
- ApplicationController.helpers.append_javascript_pack_tag("generated/#{component_name}")
328
- ApplicationController.helpers.append_stylesheet_pack_tag("generated/#{component_name}")
319
+ append_javascript_pack_tag("generated/#{component_name}",
320
+ defer: ReactOnRails.configuration.defer_generated_component_packs)
321
+ append_stylesheet_pack_tag("generated/#{component_name}")
329
322
  end
330
323
 
331
324
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
@@ -446,7 +439,11 @@ module ReactOnRails
446
439
  # Create the HTML rendering part
447
440
  result = server_rendered_react_component(render_options)
448
441
 
449
- load_pack_for_component react_component_name if render_options.auto_load_bundle
442
+ if render_options.auto_load_bundle
443
+ is_component_pack_present = File.exist?(generated_components_pack_path(react_component_name))
444
+
445
+ load_pack_for_generated_component(react_component_name) if is_component_pack_present
446
+ end
450
447
 
451
448
  {
452
449
  render_options: render_options,
@@ -551,16 +548,6 @@ module ReactOnRails
551
548
  result
552
549
  end
553
550
 
554
- def raise_missing_pack_error(component_name)
555
- msg = <<~MSG
556
- **ERROR** ReactOnRails: Generated missing pack for Component: #{component_name}. Please restart the webpack dev server or webpack in watch mode, to ensure webpack generates the chunks corresponding to #{component_name} component. If the problem persists
557
- 1. Verify `components_subdirectory` is configured in `config/initializers/react_on_rails`.
558
- 2. Component: #{component_name} is placed inside the configured `components_subdirectory`.
559
- MSG
560
-
561
- raise ReactOnRails::Error, msg
562
- end
563
-
564
551
  def replay_console_option(val)
565
552
  val.nil? ? ReactOnRails.configuration.replay_console : val
566
553
  end
@@ -78,6 +78,8 @@ module ReactOnRails
78
78
  end
79
79
 
80
80
  def add_generated_pack_to_server_bundle
81
+ return if ReactOnRails.configuration.make_generated_server_bundle_the_entrypoint
82
+
81
83
  relative_path_to_generated_server_bundle = relative_path(server_bundle_entrypoint,
82
84
  generated_server_bundle_file_path)
83
85
  content = <<~FILE_CONTENT
@@ -93,11 +95,15 @@ module ReactOnRails
93
95
  end
94
96
 
95
97
  def generated_server_bundle_file_path
98
+ return server_bundle_entrypoint if ReactOnRails.configuration.make_generated_server_bundle_the_entrypoint
99
+
96
100
  generated_server_bundle_file_path = server_bundle_entrypoint.sub(".js", "-generated.js")
97
101
  generated_server_bundle_file_name = component_name(generated_server_bundle_file_path)
98
- source_entry_path = ReactOnRails::WebpackerUtils.webpacker_source_entry_path
102
+ source_entrypoint_parent = Pathname(ReactOnRails::WebpackerUtils.webpacker_source_entry_path).parent
103
+ generated_nonentrypoints_path = "#{source_entrypoint_parent}/generated"
99
104
 
100
- "#{source_entry_path}/#{generated_server_bundle_file_name}.js"
105
+ FileUtils.mkdir_p(generated_nonentrypoints_path)
106
+ "#{generated_nonentrypoints_path}/#{generated_server_bundle_file_name}.js"
101
107
  end
102
108
 
103
109
  def clean_generated_packs_directory
@@ -214,12 +220,11 @@ module ReactOnRails
214
220
 
215
221
  def stale_or_missing_packs?
216
222
  component_files = common_component_to_path.values + client_component_to_path.values
217
- most_recent_mtime = Utils.find_most_recent_mtime(component_files)
223
+ most_recent_mtime = Utils.find_most_recent_mtime(component_files).to_i
218
224
 
219
225
  component_files.each_with_object([]).any? do |file|
220
226
  path = generated_pack_path(file)
221
-
222
- !File.exist?(path) || File.mtime(path) < most_recent_mtime
227
+ !File.exist?(path) || File.mtime(path).to_i < most_recent_mtime
223
228
  end
224
229
  end
225
230
  end
@@ -37,7 +37,7 @@ module ReactOnRails
37
37
  # All done if no stale files!
38
38
  return if stale_gen_files.empty?
39
39
 
40
- ReactOnRails::PacksGenerator.instance.generate_packs_if_stale
40
+ ReactOnRails::PacksGenerator.instance.generate_packs_if_stale if ReactOnRails.configuration.auto_load_bundle
41
41
 
42
42
  # Inform the developer that we're ensuring gen assets are ready.
43
43
  puts_start_compile_check_message(stale_gen_files)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReactOnRails
4
- VERSION = "13.3.2"
4
+ VERSION = "13.3.4"
5
5
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "13.3.2",
3
+ "version": "13.3.4",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
@@ -16,7 +16,12 @@ namespace :dummy_apps do
16
16
  bundle_install_in(dummy_app_dir)
17
17
  end
18
18
 
19
- task dummy_apps: %i[dummy_app node_package] do
19
+ task :generate_packs do
20
+ dummy_app_dir = File.join(gem_root, "spec/dummy")
21
+ sh_in_dir(dummy_app_dir, "bundle exec rake react_on_rails:generate_packs")
22
+ end
23
+
24
+ task dummy_apps: %i[dummy_app node_package generate_packs] do
20
25
  puts "Prepared all Dummy Apps"
21
26
  end
22
27
  end
@@ -20,15 +20,11 @@ namespace :run_rspec do
20
20
 
21
21
  desc "Runs dummy rspec with turbolinks"
22
22
  task dummy: ["dummy_apps:dummy_app"] do
23
- clean_gen_assets(spec_dummy_dir)
24
- bundle_install_in(dummy_app_dir)
25
23
  run_tests_in(spec_dummy_dir)
26
24
  end
27
25
 
28
26
  desc "Runs dummy rspec without turbolinks"
29
27
  task dummy_no_turbolinks: ["dummy_apps:dummy_app"] do
30
- clean_gen_assets(spec_dummy_dir)
31
- bundle_install_in(dummy_app_dir)
32
28
  run_tests_in(spec_dummy_dir,
33
29
  env_vars: "DISABLE_TURBOLINKS=TRUE",
34
30
  command_name: "dummy_no_turbolinks")
@@ -47,15 +43,10 @@ namespace :run_rspec do
47
43
  ExampleType.all.each { |example_type| Rake::Task[example_type.rspec_task_name].invoke }
48
44
  end
49
45
 
50
- desc "(HACK) Run RSpec on spec/empty_spec in order to have SimpleCov generate a coverage report from cache"
51
- task :empty do
52
- sh %(#{ENV['USE_COVERALLS'] ? 'COVERAGE=true' : ''} rspec spec/empty_spec.rb)
53
- end
54
-
55
46
  Coveralls::RakeTask.new if ENV["USE_COVERALLS"] == "TRUE"
56
47
 
57
48
  desc "run all tests no examples"
58
- task all_but_examples: %i[gem dummy_no_turbolinks dummy empty js_tests] do
49
+ task all_but_examples: %i[gem dummy_no_turbolinks dummy js_tests] do
59
50
  puts "Completed all RSpec tests"
60
51
  end
61
52
 
@@ -110,8 +101,3 @@ def run_tests_in(dir, options = {})
110
101
  env_vars << "COVERAGE=true" if ENV["USE_COVERALLS"]
111
102
  sh_in_dir(path.realpath, "#{env_vars} bundle exec rspec #{rspec_args}")
112
103
  end
113
-
114
- def clean_gen_assets(dir)
115
- path = calc_path(dir)
116
- sh_in_dir(path.realpath, "yarn run build:clean")
117
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.3.2
4
+ version: 13.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-24 00:00:00.000000000 Z
11
+ date: 2023-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -124,6 +124,7 @@ files:
124
124
  - ".github/FUNDING.yml"
125
125
  - ".github/ISSUE_TEMPLATE/bug_report.md"
126
126
  - ".github/ISSUE_TEMPLATE/feature_request.md"
127
+ - ".github/PULL_REQUEST_TEMPLATE.md"
127
128
  - ".github/workflows/lint-js-and-ruby.yml"
128
129
  - ".github/workflows/main.yml"
129
130
  - ".github/workflows/package-js-tests.yml"