react_on_rails 12.0.3.beta.0 → 12.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +12 -2
  3. data/.eslintrc +2 -1
  4. data/.github/workflows/lint-js-and-ruby.yml +3 -3
  5. data/.github/workflows/main.yml +6 -6
  6. data/.github/workflows/package-js-tests.yml +2 -2
  7. data/.github/workflows/rspec-package-specs.yml +2 -2
  8. data/.prettierrc +0 -3
  9. data/.rubocop.yml +46 -38
  10. data/CHANGELOG.md +32 -13
  11. data/CONTRIBUTING.md +3 -2
  12. data/Gemfile +1 -33
  13. data/Gemfile.development_dependencies +51 -0
  14. data/NEWS.md +0 -1
  15. data/README.md +63 -55
  16. data/docs/{basics → additional-details}/generator-details.md +1 -6
  17. data/docs/{outdated → additional-details}/manual-installation-overview.md +6 -6
  18. data/docs/{basics → additional-details}/migrating-from-react-rails.md +0 -0
  19. data/docs/{additional-reading → additional-details}/recommended-project-structure.md +0 -0
  20. data/docs/{additional-reading → additional-details}/updating-dependencies.md +0 -0
  21. data/docs/additional-details/upgrade-webpacker-v3-to-v4.md +10 -0
  22. data/docs/api/javascript-api.md +2 -2
  23. data/docs/api/redux-store-api.md +3 -3
  24. data/docs/api/view-helpers-api.md +7 -8
  25. data/docs/basics/client-vs-server-rendering.md +3 -3
  26. data/docs/basics/configuration.md +42 -25
  27. data/docs/basics/deployment.md +2 -2
  28. data/docs/{outdated → basics}/how-react-on-rails-works.md +8 -9
  29. data/docs/basics/installation-into-an-existing-rails-app.md +13 -6
  30. data/docs/basics/react-server-rendering.md +3 -3
  31. data/docs/basics/rspec-configuration.md +10 -10
  32. data/docs/{tutorial.md → basics/tutorial.md} +23 -31
  33. data/docs/basics/upgrading-react-on-rails.md +32 -12
  34. data/docs/basics/webpack-configuration.md +4 -6
  35. data/docs/contributor-info/linters.md +5 -6
  36. data/docs/contributor-info/pull-requests.md +2 -4
  37. data/docs/contributor-info/releasing.md +1 -1
  38. data/docs/{additional-reading → deployment}/elastic-beanstalk.md +0 -0
  39. data/docs/{basics → deployment}/heroku-deployment.md +0 -0
  40. data/docs/home.md +382 -0
  41. data/docs/{additional-reading → javascript}/angular-js-integration-migration.md +0 -0
  42. data/docs/{additional-reading → javascript}/asset-pipeline.md +0 -0
  43. data/docs/{additional-reading → javascript}/capistrano-deployment.md +0 -0
  44. data/docs/{outdated → javascript}/code-splitting.md +5 -5
  45. data/docs/{additional-reading → javascript}/converting-from-custom-webpack-config-to-rails-webpacker-config.md +3 -3
  46. data/docs/{additional-reading → javascript}/credits.md +0 -0
  47. data/docs/{additional-reading → javascript}/foreman-issues.md +0 -0
  48. data/docs/{additional-reading → javascript}/images.md +5 -6
  49. data/docs/{additional-reading → javascript}/node-dependencies-and-npm.md +0 -0
  50. data/docs/{additional-reading → javascript}/react-and-redux.md +0 -0
  51. data/docs/{additional-reading → javascript}/react-helmet.md +0 -0
  52. data/docs/{additional-reading → javascript}/react-router.md +0 -0
  53. data/docs/{additional-reading → javascript}/server-rendering-tips.md +0 -0
  54. data/docs/{additional-reading → javascript}/troubleshooting-when-using-webpacker.md +0 -0
  55. data/docs/{additional-reading → javascript}/webpack-v1-notes.md +0 -0
  56. data/docs/{additional-reading → javascript}/webpack.md +0 -0
  57. data/docs/{articles.md → misc/articles.md} +1 -1
  58. data/docs/misc/doctrine.md +5 -5
  59. data/docs/{coding-style → misc}/style.md +0 -0
  60. data/docs/{additional-reading → misc}/tips.md +0 -0
  61. data/docs/outdated/deferred-rendering.md +39 -0
  62. data/docs/outdated/rails-assets-relative-paths.md +3 -3
  63. data/docs/outdated/rails-assets.md +8 -8
  64. data/docs/outdated/rails3.md +2 -2
  65. data/docs/rails-webpacker-react-integration-options.md +182 -0
  66. data/docs/{additional-reading → rails}/convert-rails-5-api-only-app.md +1 -1
  67. data/docs/{additional-reading → rails}/rails-engine-integration.md +0 -0
  68. data/docs/{additional-reading → rails}/rails_view_rendering_from_inline_javascript.md +0 -0
  69. data/docs/{additional-reading → rails}/turbolinks.md +0 -0
  70. data/docs/testimonials/testimonials.md +6 -6
  71. data/lib/generators/react_on_rails/base_generator.rb +8 -1
  72. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
  73. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +4 -1
  74. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +1 -1
  75. data/lib/generators/react_on_rails/templates/dev_tests/spec/{features → system}/hello_world_spec.rb +2 -2
  76. data/lib/react_on_rails/configuration.rb +2 -0
  77. data/lib/react_on_rails/git_utils.rb +3 -3
  78. data/lib/react_on_rails/helper.rb +30 -11
  79. data/lib/react_on_rails/locales/base.rb +3 -3
  80. data/lib/react_on_rails/locales/to_js.rb +0 -4
  81. data/lib/react_on_rails/locales/to_json.rb +0 -4
  82. data/lib/react_on_rails/prerender_error.rb +1 -1
  83. data/lib/react_on_rails/react_component/render_options.rb +16 -7
  84. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +8 -6
  85. data/lib/react_on_rails/test_helper.rb +2 -0
  86. data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +1 -1
  87. data/lib/react_on_rails/utils.rb +19 -3
  88. data/lib/react_on_rails/version.rb +1 -1
  89. data/lib/react_on_rails/webpacker_utils.rb +5 -1
  90. data/lib/tasks/assets.rake +20 -11
  91. data/package.json +24 -29
  92. data/rakelib/docker.rake +0 -5
  93. data/rakelib/lint.rake +3 -9
  94. data/rakelib/release.rake +29 -15
  95. data/rakelib/run_rspec.rake +10 -11
  96. data/rakelib/task_helpers.rb +16 -4
  97. data/react_on_rails.gemspec +3 -17
  98. data/yarn.lock +2549 -5169
  99. metadata +48 -228
  100. data/.release-it.json +0 -3
  101. data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +0 -10
  102. data/docs/additional-reading/webpack-dev-server.md +0 -15
  103. data/ruby-lint.yml +0 -25
@@ -16,4 +16,4 @@ Rails will start creating the app and will skip the files you have already creat
16
16
  3. If it is removeing some of your code then press "n" and add all additions manually
17
17
  ```
18
18
 
19
- 3. Run `bundle install` and follow [the instructions for installing into an existing Rails app](../basics/installation-into-an-existing-rails-app.md).*
19
+ 3. Run `bundle install` and follow [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/basics/installation-into-an-existing-rails-app)
File without changes
@@ -1,17 +1,17 @@
1
1
  # Testimonials
2
- # [HVMN Testimonial, Written by Paul Benigeri, October 12, 2018](./hvmn.md)
2
+ # [HVMN Testimonial, Written by Paul Benigeri, October 12, 2018](https://www.shakacode.com/react-on-rails/docs/testimonials/hvmn)
3
3
 
4
4
  > The price we paid for the consultation + the React on Rails pro license has already been made back a couple of times from hosting fees alone. The entire process was super hands off, and our core team was able to focus on shipping new feature during that sprint.
5
5
 
6
- Full writeup [here](./hvmn.md).
6
+ Full writeup [here](https://www.shakacode.com/react-on-rails/docs/testimonials/hvmn).
7
7
 
8
8
  ---
9
9
 
10
- # [Leora from ResortPass](./resortpass.md), December 10, 2018
10
+ # [Leora from ResortPass](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass), December 10, 2018
11
11
 
12
- Justin and his team were instrumental in assisting us in setting design foundations and standards for our transition to a react on rails application. Just three months of work with the team at Shaka code and we have a main page of our application server-side rendering at exponentially improved speeds.
12
+ Justin and his team were instrumental in assisting us in setting design foundations and standards for our transition to a react on rails application. Just three months of work with the team at Shaka code and we have a main page of our application server-side rendering at exponentially improved speeds.
13
13
 
14
- Full writeup [here](./testimonials/resortpass.md).
14
+ Full writeup [here](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass).
15
15
 
16
16
  ---
17
17
 
@@ -25,4 +25,4 @@ From Kyle Maune of Cooper Aerial, May 4, 2018
25
25
 
26
26
  ![image](https://user-images.githubusercontent.com/1118459/40891236-9b0b406e-671d-11e8-80ee-c026dbd1d5a2.png)
27
27
 
28
- For more testimonials, see [Live Projects](PROJECTS.md) and [Kudos](KUDOS.md).
28
+ For more testimonials, see [Live Projects](https://github.com/shakacode/react_on_rails/tree/master/PROJECTS.md) and [Kudos](https://github.com/shakacode/react_on_rails/tree/master/KUDOS.md).
@@ -43,7 +43,14 @@ module ReactOnRails
43
43
  end
44
44
 
45
45
  def add_yarn_dependencies
46
- run "yarn add react-on-rails --exact"
46
+ major_minor_patch_only = /\A\d+\.\d+\.\d+\z/.freeze
47
+ if ReactOnRails::VERSION.match?(major_minor_patch_only)
48
+ run "yarn add react-on-rails@#{ReactOnRails::VERSION} --exact"
49
+ else
50
+ # otherwise add latest
51
+ puts "Adding the lastest react-on-rails NPM module. Double check this is correct in package.json"
52
+ run "yarn add react-on-rails --exact"
53
+ end
47
54
  end
48
55
 
49
56
  def append_to_spec_rails_helper
@@ -25,7 +25,7 @@ module ReactOnRails
25
25
  end
26
26
 
27
27
  def copy_tests
28
- %w[spec/features/hello_world_spec.rb].each { |file| copy_file(file) }
28
+ %w[spec/system/hello_world_spec.rb].each { |file| copy_file(file) }
29
29
  end
30
30
 
31
31
  def add_test_related_gems_to_gemfile
@@ -13,7 +13,6 @@ require_relative "spec_helper"
13
13
  require "rspec/rails"
14
14
  require "capybara/rspec"
15
15
  require "capybara/rails"
16
- Capybara.javascript_driver = :selenium_chrome
17
16
  Capybara.register_driver :selenium_chrome do |app|
18
17
  options = Selenium::WebDriver::Chrome::Options.new
19
18
  options.add_argument("--headless")
@@ -41,6 +40,10 @@ end
41
40
  # ActiveRecord::Migration.maintain_test_schema!
42
41
 
43
42
  RSpec.configure do |config|
43
+ config.before(:each, type: :system, js: true) do
44
+ driven_by :selenium_chrome
45
+ end
46
+
44
47
  # Ensure that if we are running js tests, we are using latest webpack assets
45
48
  # This will use the defaults of :js and :server_rendering meta tags
46
49
  ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
@@ -17,7 +17,7 @@ if ENV["COVERAGE"] == "true"
17
17
 
18
18
  # Don't report anything that has "spec" in the path
19
19
  add_filter do |src|
20
- src.filename =~ %r{\/spec\/}
20
+ src.filename.include?("/spec/")
21
21
  end
22
22
  end
23
23
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  require_relative "../rails_helper"
4
4
 
5
- feature "Hello World", js: true do
6
- scenario "the hello world example works" do
5
+ describe "Hello World", js: true do
6
+ it "the hello world example works" do
7
7
  visit "/hello_world"
8
8
  expect(heading).to have_text("Hello World")
9
9
  expect(message).to have_text("Stranger")
@@ -53,6 +53,7 @@ module ReactOnRails
53
53
  :server_render_method, :random_dom_id,
54
54
  :same_bundle_for_client_and_server
55
55
 
56
+ # rubocop:disable Metrics/AbcSize
56
57
  def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender: nil,
57
58
  replay_console: nil,
58
59
  trace: nil, development_mode: nil,
@@ -98,6 +99,7 @@ module ReactOnRails
98
99
 
99
100
  self.server_render_method = server_render_method
100
101
  end
102
+ # rubocop:enable Metrics/AbcSize
101
103
 
102
104
  # on ReactOnRails
103
105
  def setup_config_values
@@ -10,10 +10,10 @@ module ReactOnRails
10
10
  status = `git status --porcelain`
11
11
  return false if $CHILD_STATUS.success? && status.empty?
12
12
 
13
- error = if !$CHILD_STATUS.success?
14
- "You do not have Git installed. Please install Git, and commit your changes before continuing"
15
- else
13
+ error = if $CHILD_STATUS.success?
16
14
  "You have uncommitted code. Please commit or stash your changes before continuing"
15
+ else
16
+ "You do not have Git installed. Please install Git, and commit your changes before continuing"
17
17
  end
18
18
  message_handler.add_error(error)
19
19
  true
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # rubocop:disable Metrics/ModuleLength
4
+ # rubocop:disable Metrics/MethodLength
4
5
  # NOTE:
5
6
  # For any heredoc JS:
6
7
  # 1. The white spacing in this file matters!
@@ -32,8 +33,8 @@ module ReactOnRails
32
33
  # Exposing the react_component_name is necessary to both a plain ReactComponent as well as
33
34
  # a generator:
34
35
  # See README.md for how to "register" your react components.
35
- # See spec/dummy/client/app/startup/serverRegistration.jsx and
36
- # spec/dummy/client/app/startup/ClientRegistration.jsx for examples of this
36
+ # See spec/dummy/client/app/packs/server-bundle.js and
37
+ # spec/dummy/client/app/packs/client-bundle.js for examples of this.
37
38
  #
38
39
  # options:
39
40
  # props: Ruby Hash or JSON string which contains the properties to pass to the react object. Do
@@ -57,14 +58,15 @@ module ReactOnRails
57
58
  server_rendered_html = internal_result[:result]["html"]
58
59
  console_script = internal_result[:result]["consoleReplayScript"]
59
60
 
60
- if server_rendered_html.is_a?(String)
61
+ case server_rendered_html
62
+ when String
61
63
  build_react_component_result_for_server_rendered_string(
62
64
  server_rendered_html: server_rendered_html,
63
65
  component_specification_tag: internal_result[:tag],
64
66
  console_script: console_script,
65
67
  render_options: internal_result[:render_options]
66
68
  )
67
- elsif server_rendered_html.is_a?(Hash)
69
+ when Hash
68
70
  msg = <<~MSG
69
71
  Use react_component_hash (not react_component) to return a Hash to your ruby view code. See
70
72
  https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/client/app/startup/ReactHelmetServerApp.jsx
@@ -169,7 +171,7 @@ module ReactOnRails
169
171
  def redux_store_hydration_data
170
172
  return if @registered_stores_defer_render.blank?
171
173
 
172
- @registered_stores_defer_render.reduce("".dup) do |accum, redux_store_data|
174
+ @registered_stores_defer_render.reduce(+"") do |accum, redux_store_data|
173
175
  accum << render_redux_store_data(redux_store_data)
174
176
  end.html_safe
175
177
  end
@@ -181,7 +183,7 @@ module ReactOnRails
181
183
  # Helper method to take javascript expression and returns the output from evaluating it.
182
184
  # If you have more than one line that needs to be executed, wrap it in an IIFE.
183
185
  # JS exceptions are caught and console messages are handled properly.
184
- # Options include:{ prerender:, trace:, raise_on_prerender_error: }
186
+ # Options include:{ prerender:, trace:, raise_on_prerender_error:, throw_js_errors: }
185
187
  def server_render_js(js_expression, options = {})
186
188
  render_options = ReactOnRails::ReactComponent::RenderOptions
187
189
  .new(react_component_name: "generic-js", options: options)
@@ -191,6 +193,8 @@ module ReactOnRails
191
193
  var htmlResult = '';
192
194
  var consoleReplayScript = '';
193
195
  var hasErrors = false;
196
+ var renderingError = null;
197
+ var renderingErrorObject = {};
194
198
 
195
199
  try {
196
200
  htmlResult =
@@ -198,9 +202,17 @@ module ReactOnRails
198
202
  return #{js_expression};
199
203
  })();
200
204
  } catch(e) {
205
+ renderingError = e;
206
+ if (#{render_options.throw_js_errors}) {
207
+ throw e;
208
+ }
201
209
  htmlResult = ReactOnRails.handleError({e: e, name: null,
202
210
  jsCode: '#{escape_javascript(js_expression)}', serverSide: true});
203
211
  hasErrors = true;
212
+ renderingErrorObject = {
213
+ message: renderingError.message,
214
+ stack: renderingError.stack,
215
+ }
204
216
  }
205
217
 
206
218
  consoleReplayScript = ReactOnRails.buildConsoleReplay();
@@ -208,7 +220,8 @@ module ReactOnRails
208
220
  return JSON.stringify({
209
221
  html: htmlResult,
210
222
  consoleReplayScript: consoleReplayScript,
211
- hasErrors: hasErrors
223
+ hasErrors: hasErrors,
224
+ renderingError: renderingErrorObject
212
225
  });
213
226
 
214
227
  })()
@@ -243,7 +256,7 @@ module ReactOnRails
243
256
  # second parameter passed to both component and store Render-Functions.
244
257
  # This method can be called from views and from the controller, as `helpers.rails_context`
245
258
  #
246
- # rubocop:disable Metrics/AbcSize
259
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
247
260
  def rails_context(server_side: true)
248
261
  # ALERT: Keep in sync with node_package/src/types/index.ts for the properties of RailsContext
249
262
  @rails_context ||= begin
@@ -254,8 +267,13 @@ module ReactOnRails
254
267
  i18nLocale: I18n.locale,
255
268
  i18nDefaultLocale: I18n.default_locale,
256
269
  rorVersion: ReactOnRails::VERSION,
270
+ # TODO: v13 just use the version if existing
257
271
  rorPro: ReactOnRails::Utils.react_on_rails_pro?
258
272
  }
273
+ if ReactOnRails::Utils.react_on_rails_pro?
274
+ result[:rorProVersion] = ReactOnRails::Utils.react_on_rails_pro_version
275
+ end
276
+
259
277
  if defined?(request) && request.present?
260
278
  # Check for encoding of the request's original_url and try to force-encoding the
261
279
  # URLs as UTF-8. This situation can occur in browsers that do not encode the
@@ -291,7 +309,7 @@ module ReactOnRails
291
309
 
292
310
  @rails_context.merge(serverSide: server_side)
293
311
  end
294
- # rubocop:enable Metrics/AbcSize
312
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
295
313
 
296
314
  private
297
315
 
@@ -486,13 +504,13 @@ module ReactOnRails
486
504
  end
487
505
 
488
506
  def initialize_redux_stores
489
- result = <<-JS.dup
507
+ result = +<<-JS
490
508
  ReactOnRails.clearHydratedStores();
491
509
  JS
492
510
 
493
511
  return result unless @registered_stores.present? || @registered_stores_defer_render.present?
494
512
 
495
- declarations = "var reduxProps, store, storeGenerator;\n".dup
513
+ declarations = +"var reduxProps, store, storeGenerator;\n"
496
514
  all_stores = (@registered_stores || []) + (@registered_stores_defer_render || [])
497
515
 
498
516
  result << all_stores.each_with_object(declarations) do |redux_store_data, memo|
@@ -521,3 +539,4 @@ module ReactOnRails
521
539
  end
522
540
  end
523
541
  # rubocop:enable Metrics/ModuleLength
542
+ # rubocop:enable Metrics/MethodLength
@@ -32,12 +32,12 @@ module ReactOnRails
32
32
  end
33
33
 
34
34
  def exist_files
35
- @exist_files ||= files.select(&File.method(:exist?))
35
+ @exist_files ||= files.select { |file| File.exist?(file) }
36
36
  end
37
37
 
38
38
  def files_are_outdated
39
- latest_yml = locale_files.map(&File.method(:mtime)).max
40
- earliest = exist_files.map(&File.method(:mtime)).min
39
+ latest_yml = locale_files.map { |file| File.mtime(file) }.max
40
+ earliest = exist_files.map { |file| File.mtime(file) }.min
41
41
  latest_yml > earliest
42
42
  end
43
43
 
@@ -5,10 +5,6 @@ require "erb"
5
5
  module ReactOnRails
6
6
  module Locales
7
7
  class ToJs < Base
8
- def initialize
9
- super
10
- end
11
-
12
8
  private
13
9
 
14
10
  def file_format
@@ -5,10 +5,6 @@ require "erb"
5
5
  module ReactOnRails
6
6
  module Locales
7
7
  class ToJson < Base
8
- def initialize
9
- super
10
- end
11
-
12
8
  private
13
9
 
14
10
  def file_format
@@ -46,7 +46,7 @@ module ReactOnRails
46
46
  private
47
47
 
48
48
  def calc_message(component_name, console_messages, err, js_code, props)
49
- message = "ERROR in SERVER PRERENDERING\n".dup
49
+ message = +"ERROR in SERVER PRERENDERING\n"
50
50
  if err
51
51
  message << <<~MSG
52
52
  Encountered error: \"#{err}\"
@@ -11,6 +11,7 @@ module ReactOnRails
11
11
 
12
12
  NO_PROPS = {}.freeze
13
13
 
14
+ # TODO: remove the required for named params
14
15
  def initialize(react_component_name: required("react_component_name"), options: required("options"))
15
16
  @react_component_name = react_component_name.camelize
16
17
  @options = options
@@ -18,12 +19,16 @@ module ReactOnRails
18
19
 
19
20
  attr_reader :react_component_name
20
21
 
22
+ def throw_js_errors
23
+ options.fetch(:throw_js_errors, false)
24
+ end
25
+
21
26
  def props
22
27
  options.fetch(:props) { NO_PROPS }
23
28
  end
24
29
 
25
30
  def random_dom_id
26
- retrieve_key(:random_dom_id)
31
+ retrieve_configuration_value_for(:random_dom_id)
27
32
  end
28
33
 
29
34
  def dom_id
@@ -49,23 +54,23 @@ module ReactOnRails
49
54
  end
50
55
 
51
56
  def prerender
52
- retrieve_key(:prerender)
57
+ retrieve_configuration_value_for(:prerender)
53
58
  end
54
59
 
55
60
  def trace
56
- retrieve_key(:trace)
61
+ retrieve_configuration_value_for(:trace)
57
62
  end
58
63
 
59
64
  def replay_console
60
- retrieve_key(:replay_console)
65
+ retrieve_configuration_value_for(:replay_console)
61
66
  end
62
67
 
63
68
  def raise_on_prerender_error
64
- retrieve_key(:raise_on_prerender_error)
69
+ retrieve_configuration_value_for(:raise_on_prerender_error)
65
70
  end
66
71
 
67
72
  def logging_on_server
68
- retrieve_key(:logging_on_server)
73
+ retrieve_configuration_value_for(:logging_on_server)
69
74
  end
70
75
 
71
76
  def to_s
@@ -76,6 +81,10 @@ module ReactOnRails
76
81
  options[key]
77
82
  end
78
83
 
84
+ def set_option(key, value)
85
+ options[key] = value
86
+ end
87
+
79
88
  private
80
89
 
81
90
  attr_reader :options
@@ -88,7 +97,7 @@ module ReactOnRails
88
97
  "#{base_dom_id}-#{SecureRandom.uuid}"
89
98
  end
90
99
 
91
- def retrieve_key(key)
100
+ def retrieve_configuration_value_for(key)
92
101
  options.fetch(key) do
93
102
  ReactOnRails.configuration.public_send(key)
94
103
  end
@@ -47,6 +47,7 @@ module ReactOnRails
47
47
  # Note, js_code does not have to be based on React.
48
48
  # js_code MUST RETURN json stringify Object
49
49
  # Calling code will probably call 'html_safe' on return value before rendering to the view.
50
+ # rubocop:disable Metrics/CyclomaticComplexity
50
51
  def exec_server_render_js(js_code, render_options, js_evaluator = nil)
51
52
  js_evaluator ||= self
52
53
  if render_options.trace
@@ -67,16 +68,15 @@ module ReactOnRails
67
68
  console_script = result["consoleReplayScript"]
68
69
  console_script_lines = console_script.split("\n")
69
70
  console_script_lines = console_script_lines[2..-2]
70
- re = /console\.(log|error)\.apply\(console, \["\[SERVER\] (?<msg>.*)"\]\);/
71
- if console_script_lines
72
- console_script_lines.each do |line|
73
- match = re.match(line)
74
- Rails.logger.info { "[react_on_rails] #{match[:msg]}" } if match
75
- end
71
+ re = /console\.(?:log|error)\.apply\(console, \["\[SERVER\] (?<msg>.*)"\]\);/
72
+ console_script_lines&.each do |line|
73
+ match = re.match(line)
74
+ Rails.logger.info { "[react_on_rails] #{match[:msg]}" } if match
76
75
  end
77
76
  end
78
77
  result
79
78
  end
79
+ # rubocop:enable Metrics/CyclomaticComplexity
80
80
 
81
81
  def trace_js_code_used(msg, js_code, file_name = "tmp/server-generated.js", force: false)
82
82
  return unless ReactOnRails.configuration.trace || force
@@ -187,8 +187,10 @@ module ReactOnRails
187
187
  end
188
188
 
189
189
  # Reimplement console methods for replaying on the client
190
+ # Save a handle to the original console if needed.
190
191
  def console_polyfill
191
192
  <<~JS
193
+ var debugConsole = console;
192
194
  var console = { history: [] };
193
195
  ['error', 'log', 'info', 'warn'].forEach(function (level) {
194
196
  console[level] = function () {