react_on_rails 13.3.5 → 14.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +100 -62
  3. data/Gemfile.development_dependencies +10 -9
  4. data/README.md +7 -2
  5. data/lib/generators/react_on_rails/adapt_for_older_shakapacker_generator.rb +41 -0
  6. data/lib/generators/react_on_rails/base_generator.rb +13 -49
  7. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
  8. data/lib/generators/react_on_rails/generator_messages.rb +40 -0
  9. data/lib/generators/react_on_rails/install_generator.rb +21 -0
  10. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +2 -2
  11. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static +2 -2
  12. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +2 -2
  13. data/lib/generators/react_on_rails/templates/base/base/config/{webpacker.yml → shakapacker.yml} +3 -3
  14. data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +3 -1
  15. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +2 -2
  16. data/lib/generators/react_on_rails/templates/dev_tests/spec/system/hello_world_spec.rb +1 -1
  17. data/lib/react_on_rails/configuration.rb +39 -25
  18. data/lib/react_on_rails/git_utils.rb +3 -3
  19. data/lib/react_on_rails/helper.rb +25 -13
  20. data/lib/react_on_rails/json_output.rb +0 -17
  21. data/lib/react_on_rails/locales/base.rb +4 -4
  22. data/lib/react_on_rails/locales/to_js.rb +1 -1
  23. data/lib/react_on_rails/packs_generator.rb +4 -4
  24. data/lib/react_on_rails/react_component/render_options.rb +1 -1
  25. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +10 -12
  26. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +3 -3
  27. data/lib/react_on_rails/test_helper.rb +2 -2
  28. data/lib/react_on_rails/utils.rb +2 -8
  29. data/lib/react_on_rails/version.rb +1 -1
  30. data/lib/react_on_rails/version_checker.rb +2 -2
  31. data/lib/react_on_rails/webpacker_utils.rb +6 -0
  32. data/lib/tasks/assets.rake +1 -1
  33. data/react_on_rails.gemspec +4 -4
  34. metadata +6 -131
  35. data/.bookignore +0 -15
  36. data/.circleci/config.yml +0 -338
  37. data/.coveralls.yml +0 -1
  38. data/.dockerignore +0 -2
  39. data/.eslintignore +0 -17
  40. data/.eslintrc +0 -53
  41. data/.github/FUNDING.yml +0 -1
  42. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -23
  43. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  44. data/.github/PULL_REQUEST_TEMPLATE.md +0 -19
  45. data/.github/workflows/lint-js-and-ruby.yml +0 -54
  46. data/.github/workflows/main.yml +0 -183
  47. data/.github/workflows/package-js-tests.yml +0 -35
  48. data/.github/workflows/rspec-package-specs.yml +0 -46
  49. data/.gitignore +0 -33
  50. data/.npmignore +0 -22
  51. data/.prettierignore +0 -14
  52. data/.prettierrc +0 -20
  53. data/.rspec +0 -2
  54. data/.rubocop.yml +0 -134
  55. data/.scss-lint.yml +0 -205
  56. data/.travis.yml +0 -61
  57. data/book.json +0 -18
  58. data/docs/additional-details/generator-details.md +0 -56
  59. data/docs/additional-details/manual-installation-overview.md +0 -30
  60. data/docs/additional-details/migrating-from-react-rails.md +0 -17
  61. data/docs/additional-details/recommended-project-structure.md +0 -69
  62. data/docs/additional-details/updating-dependencies.md +0 -31
  63. data/docs/additional-details/upgrade-webpacker-v3-to-v4.md +0 -10
  64. data/docs/api/javascript-api.md +0 -99
  65. data/docs/api/redux-store-api.md +0 -102
  66. data/docs/api/view-helpers-api.md +0 -133
  67. data/docs/contributor-info/errors-with-hooks.md +0 -45
  68. data/docs/contributor-info/generator-testing.md +0 -11
  69. data/docs/contributor-info/linters.md +0 -68
  70. data/docs/contributor-info/pull-requests.md +0 -42
  71. data/docs/contributor-info/releasing.md +0 -76
  72. data/docs/deployment/elastic-beanstalk.md +0 -63
  73. data/docs/deployment/heroku-deployment.md +0 -35
  74. data/docs/getting-started.md +0 -195
  75. data/docs/guides/client-vs-server-rendering.md +0 -27
  76. data/docs/guides/configuration.md +0 -289
  77. data/docs/guides/deployment.md +0 -5
  78. data/docs/guides/file-system-based-automated-bundle-generation.md +0 -205
  79. data/docs/guides/hmr-and-hot-reloading-with-the-webpack-dev-server.md +0 -104
  80. data/docs/guides/how-react-on-rails-works.md +0 -44
  81. data/docs/guides/how-to-conditionally-server-render-based-on-device-type.md +0 -40
  82. data/docs/guides/how-to-use-different-files-for-client-and-server-rendering.md +0 -98
  83. data/docs/guides/i18n.md +0 -87
  84. data/docs/guides/installation-into-an-existing-rails-app.md +0 -66
  85. data/docs/guides/minitest-configuration.md +0 -31
  86. data/docs/guides/rails-webpacker-react-integration-options.md +0 -213
  87. data/docs/guides/react-on-rails-overview.md +0 -30
  88. data/docs/guides/react-server-rendering.md +0 -32
  89. data/docs/guides/render-functions-and-railscontext.md +0 -205
  90. data/docs/guides/rspec-configuration.md +0 -73
  91. data/docs/guides/tutorial.md +0 -374
  92. data/docs/guides/upgrading-react-on-rails.md +0 -304
  93. data/docs/guides/webpack-configuration.md +0 -42
  94. data/docs/home.md +0 -23
  95. data/docs/javascript/angular-js-integration-migration.md +0 -28
  96. data/docs/javascript/asset-pipeline.md +0 -12
  97. data/docs/javascript/capistrano-deployment.md +0 -18
  98. data/docs/javascript/code-splitting.md +0 -165
  99. data/docs/javascript/converting-from-custom-webpack-config-to-rails-webpacker-config.md +0 -10
  100. data/docs/javascript/credits.md +0 -10
  101. data/docs/javascript/foreman-issues.md +0 -15
  102. data/docs/javascript/images.md +0 -57
  103. data/docs/javascript/node-dependencies-and-npm.md +0 -19
  104. data/docs/javascript/react-and-redux.md +0 -36
  105. data/docs/javascript/react-helmet.md +0 -100
  106. data/docs/javascript/react-router.md +0 -90
  107. data/docs/javascript/server-rendering-tips.md +0 -55
  108. data/docs/javascript/troubleshooting-when-using-webpacker.md +0 -90
  109. data/docs/javascript/webpack-v1-notes.md +0 -23
  110. data/docs/javascript/webpack.md +0 -22
  111. data/docs/misc/articles.md +0 -20
  112. data/docs/misc/code_of_conduct.md +0 -13
  113. data/docs/misc/doctrine.md +0 -77
  114. data/docs/misc/style.md +0 -33
  115. data/docs/misc/tips.md +0 -10
  116. data/docs/outdated/deferred-rendering.md +0 -39
  117. data/docs/outdated/rails-assets-relative-paths.md +0 -195
  118. data/docs/outdated/rails-assets.md +0 -77
  119. data/docs/outdated/rails3.md +0 -9
  120. data/docs/rails/convert-rails-5-api-only-app.md +0 -19
  121. data/docs/rails/rails-engine-integration.md +0 -32
  122. data/docs/rails/rails_view_rendering_from_inline_javascript.md +0 -36
  123. data/docs/rails/turbolinks.md +0 -124
  124. data/docs/react-on-rails-pro/react-on-rails-pro.md +0 -43
  125. data/docs/testimonials/hvmn.md +0 -25
  126. data/docs/testimonials/resortpass.md +0 -13
  127. data/docs/testimonials/testimonials.md +0 -28
  128. data/jest.config.js +0 -4
  129. data/package-scripts.yml +0 -49
  130. data/package.json +0 -96
  131. data/rakelib/docker.rake +0 -26
  132. data/rakelib/dummy_apps.rake +0 -30
  133. data/rakelib/example_type.rb +0 -96
  134. data/rakelib/examples.rake +0 -64
  135. data/rakelib/examples_config.yml +0 -14
  136. data/rakelib/lint.rake +0 -30
  137. data/rakelib/node_package.rake +0 -15
  138. data/rakelib/release.rake +0 -92
  139. data/rakelib/run_rspec.rake +0 -103
  140. data/rakelib/task_helpers.rb +0 -62
  141. data/script/bootstrap +0 -33
  142. data/script/release +0 -3
  143. data/script/setup +0 -23
  144. data/script/test +0 -38
  145. data/webpackConfigLoader.js +0 -71
  146. data/yarn.lock +0 -7010
@@ -37,5 +37,45 @@ module GeneratorMessages
37
37
  def clear
38
38
  @output = []
39
39
  end
40
+
41
+ def helpful_message_after_installation
42
+ <<~MSG
43
+
44
+ What to do next:
45
+
46
+ - See the documentation on https://github.com/shakacode/shakapacker#webpack-configuration
47
+ for how to customize the default webpack configuration.
48
+
49
+ - Include your webpack assets to your application layout.
50
+
51
+ <%= javascript_pack_tag 'hello-world-bundle' %>
52
+
53
+ - To start Rails server run:
54
+
55
+ ./bin/dev # Running with HMR
56
+
57
+ or
58
+
59
+ ./bin/dev-static # Running with statically created bundles, without HMR
60
+
61
+ - To server render, change this line app/views/hello_world/index.html.erb to
62
+ `prerender: true` to see server rendering (right click on page and select "view source").
63
+
64
+ <%= react_component("HelloWorldApp", props: @hello_world_props, prerender: true) %>
65
+
66
+ Alternative steps to run the app:
67
+
68
+ - Run `rails s` to start the Rails server.
69
+
70
+ - Run bin/shakapacker-dev-server to start the Webpack dev server for compilation of Webpack
71
+ assets as soon as you save. This default setup with the dev server does not work
72
+ for server rendering
73
+
74
+ - Visit http://localhost:3000/hello_world and see your React On Rails app running!
75
+
76
+ - To turn on HMR, edit config/shakapacker.yml and set HMR to true. Restart the rails server
77
+ and bin/shakapacker-dev-server. Or use Procfile.dev.
78
+ MSG
79
+ end
40
80
  end
41
81
  end
@@ -29,6 +29,7 @@ module ReactOnRails
29
29
  if installation_prerequisites_met? || options.ignore_warnings?
30
30
  invoke_generators
31
31
  add_bin_scripts
32
+ add_post_install_message
32
33
  else
33
34
  error = "react_on_rails generator prerequisites not met!"
34
35
  GeneratorMessages.add_error(error)
@@ -52,6 +53,8 @@ module ReactOnRails
52
53
  else
53
54
  invoke "react_on_rails:react_no_redux"
54
55
  end
56
+
57
+ invoke "react_on_rails:adapt_for_older_shakapacker" unless using_shakapacker_7?
55
58
  end
56
59
 
57
60
  # NOTE: other requirements for existing files such as .gitignore or application.
@@ -89,6 +92,24 @@ module ReactOnRails
89
92
 
90
93
  File.chmod(0o755, *files_to_become_excutable)
91
94
  end
95
+
96
+ def add_post_install_message
97
+ message = GeneratorMessages.helpful_message_after_installation
98
+ unless using_shakapacker_7?
99
+ message = message.gsub("config/shakapacker", "config/webpacker")
100
+ message = message.gsub("bin/shakapacker", "bin/webpacker")
101
+ end
102
+
103
+ GeneratorMessages.add_info(message)
104
+ end
105
+
106
+ def using_shakapacker_7?
107
+ shakapacker_gem = Gem::Specification.find_by_name("shakapacker")
108
+ shakapacker_gem.version.segments.first == 7
109
+ rescue Gem::MissingSpecError
110
+ # In case using Webpacker
111
+ false
112
+ end
92
113
  end
93
114
  end
94
115
  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: bin/webpacker-dev-server
5
- wp-server: SERVER_BUNDLE_ONLY=yes bin/webpacker --watch
4
+ wp-client: bin/shakapacker-dev-server
5
+ wp-server: SERVER_BUNDLE_ONLY=yes bin/shakapacker --watch
@@ -5,5 +5,5 @@ web: rails s -p 3000
5
5
  # When making frequent changes to client side assets, you will prefer building webpack assets
6
6
  # upon saving rather than when you refresh your browser page.
7
7
  # Note, if using React on Rails localization you will need to run
8
- # `bundle exec rake react_on_rails:locale` before you run bin/webpacker
9
- webpack: sh -c 'rm -rf public/packs/* || true && bin/webpacker -w'
8
+ # `bundle exec rake react_on_rails:locale` before you run bin/shakapacker
9
+ webpack: sh -c 'rm -rf public/packs/* || true && bin/shakapacker -w'
@@ -24,8 +24,8 @@ ReactOnRails.configure do |config|
24
24
  # to automatically refresh your webpack assets on every test run.
25
25
  #
26
26
  # Alternately, you can remove the `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`
27
- # and set the config/webpacker.yml option for test to true.
28
- config.build_test_command = "RAILS_ENV=test bin/webpacker"
27
+ # and set the config/shakapacker.yml option for test to true.
28
+ config.build_test_command = "RAILS_ENV=test bin/shakapacker"
29
29
 
30
30
  ################################################################################
31
31
  ################################################################################
@@ -1,11 +1,11 @@
1
- # Note: You must restart bin/webpacker-dev-server for changes to take effect
1
+ # Note: You must restart bin/shakapacker-dev-server for changes to take effect
2
2
 
3
3
  default: &default
4
4
  source_path: app/javascript
5
5
  source_entry_path: packs
6
6
  public_root_path: public
7
7
  public_output_path: packs
8
- cache_path: tmp/webpacker
8
+ cache_path: tmp/shakapacker
9
9
  webpack_compile_output: true
10
10
 
11
11
  # Additional paths webpack should lookup modules
@@ -17,7 +17,7 @@ default: &default
17
17
 
18
18
  development:
19
19
  <<: *default
20
- # This is false since we're running `bin/webpacker -w` in Procfile.dev-setic
20
+ # This is false since we're running `bin/shakapacker -w` in Procfile.dev-static
21
21
  compile: false
22
22
 
23
23
  # Reference: https://webpack.js.org/configuration/dev-server/
@@ -1,7 +1,9 @@
1
1
  <%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/commonWebpackConfig.js") %>
2
2
 
3
3
  // Common configuration applying to client and server configuration
4
- const { webpackConfig: baseClientWebpackConfig, merge } = require('shakapacker');
4
+ const { generateWebpackConfig, merge } = require('shakapacker');
5
+
6
+ const baseClientWebpackConfig = generateWebpackConfig();
5
7
 
6
8
  const commonOptions = {
7
9
  resolve: {
@@ -40,7 +40,7 @@ end
40
40
  # ActiveRecord::Migration.maintain_test_schema!
41
41
 
42
42
  RSpec.configure do |config|
43
- config.before(:each, type: :system, js: true) do
43
+ config.before(:each, :js, type: :system) do
44
44
  driven_by :selenium_chrome
45
45
  end
46
46
 
@@ -49,7 +49,7 @@ RSpec.configure do |config|
49
49
  ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
50
50
 
51
51
  # Remove this line if you"re not using ActiveRecord or ActiveRecord fixtures
52
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
52
+ config.fixture_path = "#{Rails.root}/spec/fixtures"
53
53
 
54
54
  # If you"re not using ActiveRecord, or you"d prefer not to run each of your
55
55
  # examples within a transaction, remove the following line or assign false
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative "../rails_helper"
4
4
 
5
- describe "Hello World", js: true do
5
+ describe "Hello World", :js do
6
6
  it "the hello world example works" do
7
7
  visit "/hello_world"
8
8
  expect(heading).to have_text("Hello World")
@@ -137,35 +137,23 @@ module ReactOnRails
137
137
  end
138
138
 
139
139
  def adjust_precompile_task
140
- skip_react_on_rails_precompile = %w[no false n f].include?(ENV["REACT_ON_RAILS_PRECOMPILE"])
140
+ skip_react_on_rails_precompile = %w[no false n f].include?(ENV.fetch("REACT_ON_RAILS_PRECOMPILE", nil))
141
141
 
142
142
  return if skip_react_on_rails_precompile || build_production_command.blank?
143
143
 
144
- if Webpacker.config.webpacker_precompile?
145
- msg = <<~MSG
146
-
147
- React on Rails and Shakapacker error in configuration!
148
- In order to use config/react_on_rails.rb config.build_production_command,
149
- you must edit config/webpacker.yml to include this value in the default configuration:
150
- 'webpacker_precompile: false'
151
-
152
- Alternatively, remove the config/react_on_rails.rb config.build_production_command and the
153
- default bin/webpacker script will be used for assets:precompile.
154
-
155
- MSG
156
- raise ReactOnRails::Error, msg
157
- end
144
+ raise(ReactOnRails::Error, compile_command_conflict_message) if shakapacker_precompile?
158
145
 
159
146
  precompile_tasks = lambda {
160
147
  Rake::Task["react_on_rails:generate_packs"].invoke
161
148
  Rake::Task["react_on_rails:assets:webpack"].invoke
162
- puts "Invoking task webpacker:clean from React on Rails"
163
149
 
164
150
  # VERSIONS is per the shakacode/shakapacker clean method definition.
165
151
  # We set it very big so that it is not used, and then clean just
166
152
  # removes files older than 1 hour.
167
153
  versions = 100_000
168
- Rake::Task["webpacker:clean"].invoke(versions)
154
+
155
+ puts "Invoking task #{shakapacker_clean_task} from React on Rails"
156
+ Rake::Task[shakapacker_clean_task].invoke(versions)
169
157
  }
170
158
 
171
159
  if Rake::Task.task_defined?("assets:precompile")
@@ -187,7 +175,7 @@ module ReactOnRails
187
175
  webpacker_public_output_path = ReactOnRails::WebpackerUtils.webpacker_public_output_path
188
176
 
189
177
  if File.expand_path(generated_assets_dir) == webpacker_public_output_path.to_s
190
- Rails.logger.warn("You specified generated_assets_dir in `config/initializers/react_on_rails.rb` "\
178
+ Rails.logger.warn("You specified generated_assets_dir in `config/initializers/react_on_rails.rb` " \
191
179
  "with Webpacker. Remove this line from your configuration file.")
192
180
  else
193
181
  msg = <<~MSG
@@ -225,20 +213,20 @@ module ReactOnRails
225
213
 
226
214
  if ReactOnRails::WebpackerUtils.using_webpacker?
227
215
  webpacker_public_output_path = ReactOnRails::WebpackerUtils.webpacker_public_output_path
228
- Rails.logger.warn "Error configuring config/initializers/react_on_rails. Define neither the "\
229
- "generated_assets_dirs no the generated_assets_dir when using Webpacker. This is defined by "\
230
- "public_output_path specified in webpacker.yml = #{webpacker_public_output_path}."
216
+ Rails.logger.warn "Error configuring config/initializers/react_on_rails. Define neither the " \
217
+ "generated_assets_dirs no the generated_assets_dir when using Webpacker. This is defined " \
218
+ "by public_output_path specified in webpacker.yml = #{webpacker_public_output_path}."
231
219
  return
232
220
  end
233
221
 
234
- Rails.logger.warn "[DEPRECATION] ReactOnRails: Use config.generated_assets_dir rather than "\
222
+ Rails.logger.warn "[DEPRECATION] ReactOnRails: Use config.generated_assets_dir rather than " \
235
223
  "generated_assets_dirs"
236
224
  if generated_assets_dir.blank?
237
225
  self.generated_assets_dir = generated_assets_dirs
238
226
  else
239
- Rails.logger.warn "[DEPRECATION] ReactOnRails. You have both generated_assets_dirs and "\
240
- "generated_assets_dir defined. Define ONLY generated_assets_dir if NOT using Webpacker"\
241
- " and define neither if using Webpacker"
227
+ Rails.logger.warn "[DEPRECATION] ReactOnRails. You have both generated_assets_dirs and " \
228
+ "generated_assets_dir defined. Define ONLY generated_assets_dir if NOT using Webpacker " \
229
+ "and define neither if using Webpacker"
242
230
  end
243
231
  end
244
232
 
@@ -266,6 +254,32 @@ module ReactOnRails
266
254
 
267
255
  raise ReactOnRails::Error, msg
268
256
  end
257
+
258
+ def shakapacker_precompile?
259
+ return Webpacker.config.webpacker_precompile? if ReactOnRails::WebpackerUtils.using_shakapacker_6?
260
+
261
+ Webpacker.config.shakapacker_precompile?
262
+ end
263
+
264
+ def shakapacker_clean_task
265
+ ReactOnRails::WebpackerUtils.using_shakapacker_6? ? "webpacker:clean" : "shakapacker:clean"
266
+ end
267
+
268
+ def compile_command_conflict_message
269
+ packer = ReactOnRails::WebpackerUtils.using_shakapacker_6? ? "webpacker" : "shakapacker"
270
+
271
+ <<~MSG
272
+
273
+ React on Rails and Shakapacker error in configuration!
274
+ In order to use config/react_on_rails.rb config.build_production_command,
275
+ you must edit config/#{packer}.yml to include this value in the default configuration:
276
+ '#{packer}_precompile: false'
277
+
278
+ Alternatively, remove the config/react_on_rails.rb config.build_production_command and the
279
+ default bin/#{packer} script will be used for assets:precompile.
280
+
281
+ MSG
282
+ end
269
283
  end
270
284
  end
271
285
  # rubocop:enable Metrics/ClassLength
@@ -4,13 +4,13 @@ require "English"
4
4
 
5
5
  module ReactOnRails
6
6
  module GitUtils
7
- def self.uncommitted_changes?(message_handler)
7
+ def self.uncommitted_changes?(message_handler, git_installed = true)
8
8
  return false if ENV["COVERAGE"] == "true"
9
9
 
10
10
  status = `git status --porcelain`
11
- return false if $CHILD_STATUS.success? && status.empty?
11
+ return false if git_installed && status&.empty?
12
12
 
13
- error = if $CHILD_STATUS.success?
13
+ error = if git_installed
14
14
  "You have uncommitted code. Please commit or stash your changes before continuing"
15
15
  else
16
16
  "You do not have Git installed. Please install Git, and commit your changes before continuing"
@@ -155,7 +155,7 @@ module ReactOnRails
155
155
  if defer
156
156
  @registered_stores_defer_render ||= []
157
157
  @registered_stores_defer_render << redux_store_data
158
- "YOU SHOULD NOT SEE THIS ON YOUR VIEW -- Uses as a code block, like <% redux_store %> "\
158
+ "YOU SHOULD NOT SEE THIS ON YOUR VIEW -- Uses as a code block, like <% redux_store %> " \
159
159
  "and not <%= redux store %>"
160
160
  else
161
161
  @registered_stores ||= []
@@ -245,7 +245,7 @@ module ReactOnRails
245
245
  return "{}" if hash_or_string.nil?
246
246
 
247
247
  unless hash_or_string.is_a?(String) || hash_or_string.is_a?(Hash)
248
- raise ReactOnRails::Error, "#{__method__} only accepts String or Hash as argument "\
248
+ raise ReactOnRails::Error, "#{__method__} only accepts String or Hash as argument " \
249
249
  "(#{hash_or_string.class} given)."
250
250
  end
251
251
 
@@ -313,20 +313,25 @@ module ReactOnRails
313
313
  @rails_context.merge(serverSide: server_side)
314
314
  end
315
315
 
316
- def load_pack_for_generated_component(component_name)
317
- ReactOnRails::WebpackerUtils.raise_nested_entries_disabled unless ReactOnRails::WebpackerUtils.nested_entries?
316
+ def load_pack_for_generated_component(react_component_name, render_options)
317
+ return unless render_options.auto_load_bundle
318
318
 
319
- append_javascript_pack_tag("generated/#{component_name}",
319
+ ReactOnRails::WebpackerUtils.raise_nested_entries_disabled unless ReactOnRails::WebpackerUtils.nested_entries?
320
+ if Rails.env.development?
321
+ is_component_pack_present = File.exist?(generated_components_pack_path(react_component_name))
322
+ raise_missing_autoloaded_bundle(react_component_name) unless is_component_pack_present
323
+ end
324
+ append_javascript_pack_tag("generated/#{react_component_name}",
320
325
  defer: ReactOnRails.configuration.defer_generated_component_packs)
321
- append_stylesheet_pack_tag("generated/#{component_name}")
326
+ append_stylesheet_pack_tag("generated/#{react_component_name}")
322
327
  end
323
328
 
324
329
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
325
330
 
326
331
  private
327
332
 
328
- def generated_components_pack_path(component_name)
329
- "#{ReactOnRails::WebpackerUtils.webpacker_source_entry_path}/generated/#{component_name}.js"
333
+ def generated_components_pack_path(react_component_name)
334
+ "#{ReactOnRails::WebpackerUtils.webpacker_source_entry_path}/generated/#{react_component_name}.js"
330
335
  end
331
336
 
332
337
  def build_react_component_result_for_server_rendered_string(
@@ -439,11 +444,7 @@ module ReactOnRails
439
444
  # Create the HTML rendering part
440
445
  result = server_rendered_react_component(render_options)
441
446
 
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
447
+ load_pack_for_generated_component(react_component_name, render_options)
447
448
 
448
449
  {
449
450
  render_options: render_options,
@@ -564,6 +565,17 @@ module ReactOnRails
564
565
  instrument_method :react_component, type: "ReactOnRails", name: "react_component"
565
566
  instrument_method :react_component_hash, type: "ReactOnRails", name: "react_component_hash"
566
567
  end
568
+
569
+ def raise_missing_autoloaded_bundle(react_component_name)
570
+ msg = <<~MSG
571
+ **ERROR** ReactOnRails: Component "#{react_component_name}" is configured as "auto_load_bundle: true"
572
+ but the generated component entrypoint, which should have been at #{generated_components_pack_path(react_component_name)},
573
+ is missing. You might want to check that this component is in a directory named "#{ReactOnRails.configuration.components_subdirectory}"
574
+ & that "bundle exec rake react_on_rails:generate_packs" has been run.
575
+ MSG
576
+
577
+ raise ReactOnRails::Error, msg
578
+ end
567
579
  end
568
580
  end
569
581
  # rubocop:enable Metrics/ModuleLength
@@ -4,25 +4,8 @@ require "active_support/core_ext/string/output_safety"
4
4
 
5
5
  module ReactOnRails
6
6
  class JsonOutput
7
- ESCAPE_REPLACEMENT = {
8
- "&" => '\u0026',
9
- ">" => '\u003e',
10
- "<" => '\u003c',
11
- "\u2028" => '\u2028',
12
- "\u2029" => '\u2029'
13
- }.freeze
14
- ESCAPE_REGEXP = /[\u2028\u2029&><]/u.freeze
15
-
16
7
  def self.escape(json)
17
- return escape_without_erb_util(json) if Utils.rails_version_less_than_4_1_1
18
-
19
8
  ERB::Util.json_escape(json)
20
9
  end
21
-
22
- def self.escape_without_erb_util(json)
23
- # https://github.com/rails/rails/blob/60257141462137331387d0e34931555cf0720886/activesupport/lib/active_support/core_ext/string/output_safety.rb#L113
24
-
25
- json.to_s.gsub(ESCAPE_REGEXP, ESCAPE_REPLACEMENT)
26
- end
27
10
  end
28
11
  end
@@ -100,14 +100,14 @@ module ReactOnRails
100
100
 
101
101
  def convert
102
102
  file_names.each do |name|
103
- template = send("template_#{name}")
103
+ template = send(:"template_#{name}")
104
104
  path = file(name)
105
105
  generate_file(template, path)
106
106
  end
107
107
  end
108
108
 
109
109
  def generate_file(template, path)
110
- result = ERB.new(template).result()
110
+ result = ERB.new(template).result
111
111
  File.write(path, result)
112
112
  end
113
113
 
@@ -138,7 +138,7 @@ module ReactOnRails
138
138
  def flatten(translations)
139
139
  translations.each_with_object({}) do |(k, v), h|
140
140
  if v.is_a? Hash
141
- flatten(v).map { |hk, hv| h["#{k}.#{hk}".to_sym] = hv }
141
+ flatten(v).map { |hk, hv| h[:"#{k}.#{hk}"] = hv }
142
142
  elsif v.is_a?(String)
143
143
  h[k] = v.gsub("%{", "{")
144
144
  elsif !v.is_a?(Array)
@@ -157,7 +157,7 @@ module ReactOnRails
157
157
  <<-JS.strip_heredoc
158
158
  import { defineMessages } from 'react-intl';
159
159
 
160
- const defaultLocale = \'#{default_locale}\';
160
+ const defaultLocale = '#{default_locale}';
161
161
 
162
162
  const defaultMessages = defineMessages(#{@defaults});
163
163
 
@@ -21,7 +21,7 @@ module ReactOnRails
21
21
  <<-JS.strip_heredoc
22
22
  import { defineMessages } from 'react-intl';
23
23
 
24
- const defaultLocale = \'#{default_locale}\';
24
+ const defaultLocale = '#{default_locale}';
25
25
 
26
26
  const defaultMessages = defineMessages(#{@defaults});
27
27
 
@@ -5,7 +5,7 @@ require "fileutils"
5
5
  module ReactOnRails
6
6
  # rubocop:disable Metrics/ClassLength
7
7
  class PacksGenerator
8
- CONTAINS_CLIENT_OR_SERVER_REGEX = /\.(server|client)($|\.)/.freeze
8
+ CONTAINS_CLIENT_OR_SERVER_REGEX = /\.(server|client)($|\.)/
9
9
  MINIMUM_SHAKAPACKER_VERSION = [6, 5, 1].freeze
10
10
 
11
11
  def self.instance
@@ -13,6 +13,8 @@ module ReactOnRails
13
13
  end
14
14
 
15
15
  def generate_packs_if_stale
16
+ return unless ReactOnRails.configuration.auto_load_bundle
17
+
16
18
  are_generated_files_present_and_up_to_date = Dir.exist?(generated_packs_directory_path) &&
17
19
  File.exist?(generated_server_bundle_file_path) &&
18
20
  !stale_or_missing_packs?
@@ -153,9 +155,7 @@ module ReactOnRails
153
155
  end
154
156
 
155
157
  def common_component_to_path
156
- common_components_paths = Dir.glob("#{components_search_path}/*").reject do |f|
157
- CONTAINS_CLIENT_OR_SERVER_REGEX.match?(f)
158
- end
158
+ common_components_paths = Dir.glob("#{components_search_path}/*").grep_v(CONTAINS_CLIENT_OR_SERVER_REGEX)
159
159
  component_name_to_path(common_components_paths)
160
160
  end
161
161
 
@@ -35,7 +35,7 @@ module ReactOnRails
35
35
  props.clone)
36
36
  end
37
37
 
38
- raise ReactOnRails::Error, "ReactOnRails: your rendering_props_extension module is missing the "\
38
+ raise ReactOnRails::Error, "ReactOnRails: your rendering_props_extension module is missing the " \
39
39
  "required adjust_props_for_client_side_hydration method & can not be used"
40
40
  end
41
41
  props
@@ -7,7 +7,6 @@ module ReactOnRails
7
7
  module ServerRenderingPool
8
8
  # rubocop:disable Metrics/ClassLength
9
9
  class RubyEmbeddedJavaScript
10
- # rubocop:enable Metrics/ClassLength
11
10
  class << self
12
11
  def reset_pool
13
12
  options = {
@@ -113,9 +112,7 @@ module ReactOnRails
113
112
 
114
113
  def eval_js(js_code, _render_options)
115
114
  @js_context_pool.with do |js_context|
116
- result = js_context.eval(js_code)
117
- js_context.eval("console.history = []")
118
- result
115
+ js_context.eval(js_code)
119
116
  end
120
117
  end
121
118
 
@@ -127,8 +124,8 @@ module ReactOnRails
127
124
  File.read(server_js_file)
128
125
  end
129
126
  rescue StandardError => e
130
- msg = "You specified server rendering JS file: #{server_js_file}, but it cannot be "\
131
- "read. You may set the server_bundle_js_file in your configuration to be \"\" to "\
127
+ msg = "You specified server rendering JS file: #{server_js_file}, but it cannot be " \
128
+ "read. You may set the server_bundle_js_file in your configuration to be \"\" to " \
132
129
  "avoid this warning.\nError is: #{e}"
133
130
  raise ReactOnRails::Error, msg
134
131
  end
@@ -147,15 +144,15 @@ module ReactOnRails
147
144
  begin
148
145
  if ReactOnRails.configuration.trace
149
146
  Rails.logger.info do
150
- "[react_on_rails] Created JavaScript context with file "\
147
+ "[react_on_rails] Created JavaScript context with file " \
151
148
  "#{ReactOnRails::Utils.server_bundle_js_file_path}"
152
149
  end
153
150
  end
154
151
  ExecJS.compile(base_js_code)
155
152
  rescue StandardError => e
156
- msg = "ERROR when compiling base_js_code! "\
157
- "See file #{file_name} to "\
158
- "correlate line numbers of error. Error is\n\n#{e.message}"\
153
+ msg = "ERROR when compiling base_js_code! " \
154
+ "See file #{file_name} to " \
155
+ "correlate line numbers of error. Error is\n\n#{e.message}" \
159
156
  "\n\n#{e.backtrace.join("\n")}"
160
157
  Rails.logger.error(msg)
161
158
  trace_js_code_used("Error when compiling JavaScript code for the context.", base_js_code,
@@ -194,8 +191,8 @@ module ReactOnRails
194
191
 
195
192
  def undefined_for_exec_js_logging(function_name)
196
193
  if ReactOnRails.configuration.trace
197
- "console.error('[React on Rails Rendering] #{function_name} is not defined for server rendering.');\n"\
198
- " console.error(getStackTrace().join('\\n'));"
194
+ "console.error('[React on Rails Rendering] #{function_name} is not defined for server rendering.');\n " \
195
+ "console.error(getStackTrace().join('\\n'));"
199
196
  else
200
197
  ""
201
198
  end
@@ -237,6 +234,7 @@ module ReactOnRails
237
234
  raise ReactOnRails::Error, msg
238
235
  end
239
236
  end
237
+ # rubocop:enable Metrics/ClassLength
240
238
  end
241
239
  end
242
240
  end
@@ -62,10 +62,10 @@ module ReactOnRails
62
62
  else
63
63
  file_list = make_file_list(make_globs(generated_assets_full_path)).to_ary
64
64
  puts "V" * 80
65
- puts "Please define config.webpack_generated_files (array) so the test helper knows "\
66
- "which files are required. If you are using webpacker, you typically need to only "\
65
+ puts "Please define config.webpack_generated_files (array) so the test helper knows " \
66
+ "which files are required. If you are using webpacker, you typically need to only " \
67
67
  "include 'manifest.json'."
68
- puts "Detected the possible following files to check for webpack compilation in "\
68
+ puts "Detected the possible following files to check for webpack compilation in " \
69
69
  "#{generated_assets_full_path}"
70
70
  puts file_list.join("\n")
71
71
  puts "^" * 80
@@ -80,8 +80,8 @@ module ReactOnRails
80
80
 
81
81
  unless @printed_once
82
82
  puts
83
- puts "====> React On Rails: Checking files in "\
84
- "#{webpack_assets_status_checker.generated_assets_full_path} for "\
83
+ puts "====> React On Rails: Checking files in " \
84
+ "#{webpack_assets_status_checker.generated_assets_full_path} for " \
85
85
  "outdated/missing bundles based on source_path #{source_path}"
86
86
  puts
87
87
  @printed_once = true
@@ -118,12 +118,6 @@ module ReactOnRails
118
118
  end
119
119
  end
120
120
 
121
- # rubocop:disable Naming/VariableNumber
122
- def self.rails_version_less_than_4_1_1
123
- rails_version_less_than("4.1.1")
124
- end
125
- # rubocop:enable Naming/VariableNumber
126
-
127
121
  module Required
128
122
  def required(arg_name)
129
123
  raise ReactOnRails::Error, "#{arg_name} is required"
@@ -195,13 +189,13 @@ module ReactOnRails
195
189
  to_remove = str.length - max_length
196
190
  lstrip = (to_remove / 2.0).ceil
197
191
  rstrip = to_remove - lstrip
198
- str[0..(midpoint - lstrip - 1)] + TRUNCATION_FILLER + str[(midpoint + rstrip)..-1]
192
+ str[0..(midpoint - lstrip - 1)] + TRUNCATION_FILLER + str[(midpoint + rstrip)..]
199
193
  end
200
194
 
201
195
  def self.find_most_recent_mtime(files)
202
196
  files.reduce(1.year.ago) do |newest_time, file|
203
197
  mt = File.mtime(file)
204
- mt > newest_time ? mt : newest_time
198
+ [mt, newest_time].max
205
199
  end
206
200
  end
207
201
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReactOnRails
4
- VERSION = "13.3.5"
4
+ VERSION = "14.0.0"
5
5
  end
@@ -6,7 +6,7 @@ module ReactOnRails
6
6
  class VersionChecker
7
7
  attr_reader :node_package_version
8
8
 
9
- MAJOR_MINOR_PATCH_VERSION_REGEX = /(\d+)\.(\d+)\.(\d+)/.freeze
9
+ MAJOR_MINOR_PATCH_VERSION_REGEX = /(\d+)\.(\d+)\.(\d+)/
10
10
 
11
11
  def self.build
12
12
  new(NodePackageVersion.build)
@@ -52,7 +52,7 @@ module ReactOnRails
52
52
  end
53
53
 
54
54
  def raise_node_semver_version_warning
55
- msg = "**ERROR** ReactOnRails: Your node package version for react-on-rails contains a "\
55
+ msg = "**ERROR** ReactOnRails: Your node package version for react-on-rails contains a " \
56
56
  "^ or ~\n#{common_error_msg}"
57
57
  raise ReactOnRails::Error, msg
58
58
  end