react_on_rails 12.1.0 → 12.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +12 -10
  3. data/.rubocop.yml +2 -1
  4. data/CHANGELOG.md +39 -17
  5. data/Gemfile.development_dependencies +1 -1
  6. data/NEWS.md +9 -4
  7. data/README.md +18 -316
  8. data/Rakefile +1 -1
  9. data/SUMMARY.md +12 -12
  10. data/docs/additional-details/generator-details.md +1 -1
  11. data/docs/additional-details/manual-installation-overview.md +2 -2
  12. data/docs/api/view-helpers-api.md +4 -4
  13. data/docs/contributor-info/linters.md +1 -1
  14. data/docs/contributor-info/pull-requests.md +1 -1
  15. data/docs/{basics → guides}/client-vs-server-rendering.md +1 -1
  16. data/docs/{basics → guides}/configuration.md +5 -2
  17. data/docs/{basics → guides}/deployment.md +1 -1
  18. data/docs/guides/getting-started.md +183 -0
  19. data/docs/{basics → guides}/hmr-and-hot-reloading-with-the-webpack-dev-server.md +0 -0
  20. data/docs/{basics → guides}/how-react-on-rails-works.md +3 -1
  21. data/docs/guides/how-to-conditionally-server-render-based-on-device-type.md +39 -0
  22. data/docs/guides/how-to-use-different-files-for-client-and-server-rendering.md +98 -0
  23. data/docs/{basics → guides}/i18n.md +0 -0
  24. data/docs/{basics → guides}/installation-into-an-existing-rails-app.md +3 -3
  25. data/docs/{basics → guides}/minitest-configuration.md +0 -0
  26. data/docs/{rails-webpacker-react-integration-options.md → guides/rails-webpacker-react-integration-options.md} +1 -1
  27. data/docs/guides/react-on-rails-overview.md +30 -0
  28. data/docs/{basics → guides}/react-server-rendering.md +2 -2
  29. data/docs/{basics → guides}/render-functions-and-railscontext.md +0 -0
  30. data/docs/{basics → guides}/rspec-configuration.md +2 -2
  31. data/docs/{basics → guides}/tutorial.md +2 -4
  32. data/docs/{basics → guides}/upgrading-react-on-rails.md +1 -1
  33. data/docs/{basics → guides}/webpack-configuration.md +1 -1
  34. data/docs/home.md +19 -378
  35. data/docs/javascript/code-splitting.md +2 -2
  36. data/docs/misc/articles.md +1 -1
  37. data/docs/misc/doctrine.md +3 -3
  38. data/docs/outdated/rails-assets-relative-paths.md +2 -2
  39. data/docs/outdated/rails-assets.md +1 -1
  40. data/docs/rails/convert-rails-5-api-only-app.md +1 -1
  41. data/docs/rails/rails-engine-integration.md +3 -12
  42. data/docs/rails/turbolinks.md +13 -1
  43. data/docs/react-on-rails-pro/react-on-rails-pro.md +43 -0
  44. data/docs/testimonials/testimonials.md +4 -4
  45. data/lib/generators/react_on_rails/base_generator.rb +1 -1
  46. data/lib/react_on_rails/helper.rb +21 -2
  47. data/lib/react_on_rails/locales/base.rb +7 -9
  48. data/lib/react_on_rails/react_component/render_options.rb +16 -7
  49. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +11 -0
  50. data/lib/react_on_rails/version.rb +1 -1
  51. data/lib/tasks/assets.rake +3 -1
  52. data/package.json +1 -1
  53. data/rakelib/release.rake +3 -3
  54. data/yarn.lock +469 -401
  55. metadata +22 -18
  56. data/.release-it.json +0 -3
@@ -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!
@@ -182,7 +183,7 @@ module ReactOnRails
182
183
  # Helper method to take javascript expression and returns the output from evaluating it.
183
184
  # If you have more than one line that needs to be executed, wrap it in an IIFE.
184
185
  # JS exceptions are caught and console messages are handled properly.
185
- # Options include:{ prerender:, trace:, raise_on_prerender_error: }
186
+ # Options include:{ prerender:, trace:, raise_on_prerender_error:, throw_js_errors: }
186
187
  def server_render_js(js_expression, options = {})
187
188
  render_options = ReactOnRails::ReactComponent::RenderOptions
188
189
  .new(react_component_name: "generic-js", options: options)
@@ -192,6 +193,8 @@ module ReactOnRails
192
193
  var htmlResult = '';
193
194
  var consoleReplayScript = '';
194
195
  var hasErrors = false;
196
+ var renderingError = null;
197
+ var renderingErrorObject = {};
195
198
 
196
199
  try {
197
200
  htmlResult =
@@ -199,9 +202,17 @@ module ReactOnRails
199
202
  return #{js_expression};
200
203
  })();
201
204
  } catch(e) {
205
+ renderingError = e;
206
+ if (#{render_options.throw_js_errors}) {
207
+ throw e;
208
+ }
202
209
  htmlResult = ReactOnRails.handleError({e: e, name: null,
203
210
  jsCode: '#{escape_javascript(js_expression)}', serverSide: true});
204
211
  hasErrors = true;
212
+ renderingErrorObject = {
213
+ message: renderingError.message,
214
+ stack: renderingError.stack,
215
+ }
205
216
  }
206
217
 
207
218
  consoleReplayScript = ReactOnRails.buildConsoleReplay();
@@ -209,7 +220,8 @@ module ReactOnRails
209
220
  return JSON.stringify({
210
221
  html: htmlResult,
211
222
  consoleReplayScript: consoleReplayScript,
212
- hasErrors: hasErrors
223
+ hasErrors: hasErrors,
224
+ renderingError: renderingErrorObject
213
225
  });
214
226
 
215
227
  })()
@@ -524,6 +536,13 @@ module ReactOnRails
524
536
 
525
537
  controller.is_a?(ActionMailer::Base)
526
538
  end
539
+
540
+ if defined?(ScoutApm)
541
+ include ScoutApm::Tracer
542
+ instrument_method :react_component, type: "ReactOnRails", name: "react_component"
543
+ instrument_method :react_component_hash, type: "ReactOnRails", name: "react_component_hash"
544
+ end
527
545
  end
528
546
  end
529
547
  # rubocop:enable Metrics/ModuleLength
548
+ # rubocop:enable Metrics/MethodLength
@@ -54,15 +54,13 @@ module ReactOnRails
54
54
  end
55
55
 
56
56
  def locale_files
57
- @locale_files ||= begin
58
- if i18n_yml_dir.present?
59
- Dir["#{i18n_yml_dir}/**/*.yml"]
60
- else
61
- ReactOnRails::Utils.truthy_presence(
62
- Rails.application && Rails.application.config.i18n.load_path
63
- ).presence
64
- end
65
- end
57
+ @locale_files ||= if i18n_yml_dir.present?
58
+ Dir["#{i18n_yml_dir}/**/*.yml"]
59
+ else
60
+ ReactOnRails::Utils.truthy_presence(
61
+ Rails.application && Rails.application.config.i18n.load_path
62
+ ).presence
63
+ end
66
64
  end
67
65
 
68
66
  def i18n_dir
@@ -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
@@ -150,6 +150,10 @@ module ReactOnRails
150
150
  end
151
151
 
152
152
  def execjs_timer_polyfills
153
+ if ReactOnRails::Utils.react_on_rails_pro? && ReactOnRailsPro.configuration.include_execjs_polyfills == false
154
+ return ""
155
+ end
156
+
153
157
  <<~JS
154
158
  function getStackTrace () {
155
159
  var stack;
@@ -187,8 +191,10 @@ module ReactOnRails
187
191
  end
188
192
 
189
193
  # Reimplement console methods for replaying on the client
194
+ # Save a handle to the original console if needed.
190
195
  def console_polyfill
191
196
  <<~JS
197
+ var debugConsole = console;
192
198
  var console = { history: [] };
193
199
  ['error', 'log', 'info', 'warn'].forEach(function (level) {
194
200
  console[level] = function () {
@@ -202,6 +208,11 @@ module ReactOnRails
202
208
  JS
203
209
  end
204
210
 
211
+ if defined?(ScoutApm)
212
+ include ScoutApm::Tracer
213
+ instrument_method :exec_server_render_js, type: "ReactOnRails", name: "ExecJs React Server Rendering"
214
+ end
215
+
205
216
  private
206
217
 
207
218
  def file_url_to_string(url)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReactOnRails
4
- VERSION = "12.1.0"
4
+ VERSION = "12.4.0"
5
5
  end
@@ -7,7 +7,9 @@ require "active_support"
7
7
 
8
8
  ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
9
9
 
10
- unless ReactOnRails::WebpackerUtils.webpacker_webpack_production_config_exists?
10
+ skip_react_on_rails_precompile = %w[no false n f].include?(ENV["REACT_ON_RAILS_PRECOMPILE"])
11
+
12
+ if !skip_react_on_rails_precompile && !ReactOnRails::WebpackerUtils.webpacker_webpack_production_config_exists?
11
13
  # Ensure that rails/webpacker does not call bin/webpack if we're providing
12
14
  # the build command.
13
15
  ENV["WEBPACKER_PRECOMPILE"] = "false"
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "12.1.0",
3
+ "version": "12.4.0",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
data/rakelib/release.rake CHANGED
@@ -21,7 +21,7 @@ for the node package version. This only makes a difference for pre-release
21
21
  versions such as `3.0.0.beta.1` (yarn version would be `3.0.0-beta.1`).
22
22
 
23
23
  This task depends on the gem-release (ruby gem) and release-it (node package)
24
- which are installed via `bundle install` and `yarn`
24
+ which are installed via `bundle install` and `yarn global add release-it`
25
25
 
26
26
  1st argument: The new version in rubygem format (no dashes). Pass no argument to
27
27
  automatically perform a patch version bump.
@@ -58,9 +58,9 @@ task :release, %i[gem_version dry_run tools_install] do |_t, args|
58
58
  bundle_install_in(dummy_app_dir)
59
59
 
60
60
  # Will bump the yarn version, commit, tag the commit, push to repo, and release on yarn
61
- release_it_command = +"$(yarn bin)/release-it"
61
+ release_it_command = +"release-it"
62
62
  release_it_command << " #{npm_version}" unless npm_version.strip.empty?
63
- release_it_command << " --non-interactive --npm.publish"
63
+ release_it_command << " --ci --npm.publish --no-git.requireCleanWorkingDir"
64
64
  release_it_command << " --dry-run --verbose" if is_dry_run
65
65
  sh_in_dir(gem_root, release_it_command)
66
66