react_on_rails 17.2.1 → 17.3.0.rc.0

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: 1abbe5d638a30fe10a6b9716b50da72e4acc6af4602aa9aeea9b9ec86a5898f6
4
- data.tar.gz: a624c0a7f6ebd843359105a2c113a7a8596c1c8d00b6d585975b7cae552c3d98
3
+ metadata.gz: 49990f345ba95789472647384b6b67059062b7f03723598c18d43578da65ec89
4
+ data.tar.gz: 86c88ae46e0f8082778bff642cedfd8497fc8d7af27a0f87f2e39c0172962051
5
5
  SHA512:
6
- metadata.gz: 46e516dcc674b098fead741e3c93ed3c4555c55f74f56d4cd19604ee6c8877ddfc6ee031ad5c67bf05e09c2fefe1ae5ecb958d84b41cc452c661a22bf6fbe6b6
7
- data.tar.gz: 6a5e3cc621af429b32acd625e181695f316ebb082883c8759a155b572bd75623ee8b76ed7b1cecae907388b04891174e651ff027b6db205ed3562aecf782c436
6
+ metadata.gz: e8d9e5c3fd4b3bfc58ecb9471dd30190ee8ac69e73e2554c52bbaeea0b8cbe3511c6a138ea93854bb2c252e1feb6138a33efc4cccefdee209259d4fe82607f23
7
+ data.tar.gz: 67f0a1d5e03b78a4c2813a86968cac8e70c40a524f39310c90968412dc8c50178d8726c7ce8996bcccdcdc3f38faea61725e585ebff1b2ec3eab712c2d83ea36
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- react_on_rails (17.2.1)
4
+ react_on_rails (17.3.0.rc.0)
5
5
  addressable
6
6
  connection_pool
7
7
  execjs (~> 2.5)
@@ -25,10 +25,11 @@ SHAKAPACKER_VERSION="$(bundle exec ruby -rreact_on_rails -e 'print ReactOnRails:
25
25
  bundle add shakapacker --version="${SHAKAPACKER_VERSION}" --strict
26
26
  ```
27
27
 
28
- For `--pro` or `--rsc`, React on Rails Pro is free in development, test, CI, and staging,
29
- and in production for small organizations, charities, schools, and hospitals;
30
- larger organizations subscribe ($1,800 per year per organization).
31
- No license key is needed to run Pro. Review [pricing](https://reactonrails.com/pricing/)
28
+ For `--pro` or `--rsc`, React on Rails Pro is free in development, test, CI, and staging
29
+ solely to prepare an application before production. Qualifying organizations and
30
+ genuine evaluations can use Pro in production for free. Other production use
31
+ requires ShakaStack Pro for the whole organization ($1,800 per year).
32
+ No license key is needed to run Pro. Review [Free & Pro](https://reactonrails.com/pricing/)
32
33
  and [Pro setup](https://reactonrails.com/docs/pro/upgrading-to-pro/) before proceeding.
33
34
 
34
35
  Skip this Pro-gem preparation for `--standard-only`.
@@ -344,6 +344,7 @@ module ReactOnRails
344
344
  additions << "**/generated/**" unless gitignore_content.include?("**/generated/**")
345
345
  additions << "ssr-generated" unless gitignore_content.include?("ssr-generated")
346
346
  additions << ".env" unless gitignore_content.match?(/^\.env$/)
347
+ additions.concat(renderer_cache_gitignore_additions(gitignore_content))
347
348
 
348
349
  return if additions.empty?
349
350
 
@@ -379,6 +380,20 @@ module ReactOnRails
379
380
 
380
381
  private
381
382
 
383
+ def renderer_cache_gitignore_additions(content)
384
+ return [] unless use_pro?
385
+
386
+ lines = content.lines.map(&:chomp)
387
+ last_negation = lines.rindex { |line| line.start_with?("!") } || -1
388
+
389
+ # Ignore both the renderer cache and the sibling files created during preseeding.
390
+ %w[
391
+ .node-renderer-bundles
392
+ .node-renderer-bundles.preseed.lock
393
+ .node-renderer-bundles.artifact-snapshots
394
+ ].reject { |entry| (lines.rindex(entry) || -1) > last_negation }
395
+ end
396
+
382
397
  # Fresh-install context: default to Rspack (when Shakapacker supports it) unless the
383
398
  # app already declares a bundler. See GeneratorHelper#fresh_install_rspack_default.
384
399
  # NOTE: InstallGenerator#rspack_bundler_default is an intentional twin of this override
@@ -38,6 +38,7 @@ module ReactOnRails
38
38
  spec/spec_helper.rb
39
39
  spec/rails_helper.rb
40
40
  spec/simplecov_helper.rb
41
+ spec/support/capybara_chrome_reset.rb
41
42
  .rspec].each { |file| copy_file(file) }
42
43
  end
43
44
 
@@ -247,8 +247,9 @@ module ReactOnRails
247
247
  validate_product_stack_choice!
248
248
  return if options.new_app? || explicit_product_stack_choice? || !interactive_install_session?
249
249
 
250
- say "No license key is needed to run Pro. Production is free for small organizations, charities, schools, " \
251
- "and hospitals; larger organizations subscribe: https://reactonrails.com/pricing/"
250
+ say "No license key is needed to run Pro. Qualifying production use is free; " \
251
+ "other production use needs ShakaStack Pro for the whole organization: " \
252
+ "https://reactonrails.com/pricing/"
252
253
  say "Learn more: https://reactonrails.com/docs/pro/upgrading-to-pro/"
253
254
  answer = ask(
254
255
  "Enable React on Rails Pro features (Node Renderer and streaming SSR; RSC available separately)? [Y/n]",
@@ -152,23 +152,24 @@ module ReactOnRails
152
152
 
153
153
  # React peer-dependency range for generated RSC apps. This governs the `react` / `react-dom`
154
154
  # installs (see add_react_dependencies) and stays on the single React minor that the pinned
155
- # `react-on-rails-rsc` package bundles Flight for: 19.3.1 peers on React ^19.3.0. Do not widen
155
+ # `react-on-rails-rsc` package bundles Flight for: 19.3.2 peers on React ^19.3.1. Do not widen
156
156
  # this to later minors just because those releases are current on npm; React's RSC runtime and
157
157
  # bundler integration can change between minors. Move it together with RSC_PACKAGE_VERSION_PIN.
158
158
  #
159
- # The floor is 19.3.1, stricter than the ^19.3.0 that react-on-rails-rsc 19.3.1 accepts: React's
160
- # 2026-10-14 RSC advisories (GHSA-xqc2-xf4c-x3h3, GHSA-h3gv-c5rc-p453) affect
161
- # react-server-dom-webpack 19.3.0, and the patched react-server-dom-webpack 19.3.1 peers on React
162
- # ^19.3.1. A ~19.3.0 range would let a lockfile keep the vulnerable set.
159
+ # The floor is 19.3.1 because React's 2026-10-14 RSC advisories (GHSA-xqc2-xf4c-x3h3,
160
+ # GHSA-h3gv-c5rc-p453) affect react-server-dom-webpack 19.3.0. react-on-rails-rsc 19.3.2 depends
161
+ # on the patched react-server-dom-webpack ~19.3.1, which peers on React ^19.3.1, so this range
162
+ # matches the pinned package's own peer floor.
163
163
  #
164
164
  # This is intentionally distinct from RSC_PACKAGE_VERSION_PIN below, which pins
165
165
  # `react-on-rails-rsc`. Coordination note for #3609: generated apps use this React range with
166
166
  # the exact stable RSC package pin; the Pro packages' dev pins track the tested React release.
167
167
  RSC_REACT_VERSION_RANGE = "~19.3.1"
168
- # Pinned to the stable 19.3.1 package, the current React 19.3 line. Apps generated by earlier
169
- # versions keep their own pins (19.2.x with React 19.2.7+, or 19.3.0 with React 19.2.8+), which
170
- # the React on Rails Pro 17 runtime check still supports.
171
- RSC_PACKAGE_VERSION_PIN = "19.3.1"
168
+ # Pinned to the stable 19.3.2 package, the first React 19.3 release that requires the patched
169
+ # Flight runtime. Apps generated by earlier versions keep their own pins (19.2.x with React
170
+ # 19.2.7+, 19.3.0 with React 19.2.8+, or 19.3.1 with React 19.3.0+), which the React on Rails
171
+ # Pro 17 runtime check still supports.
172
+ RSC_PACKAGE_VERSION_PIN = "19.3.2"
172
173
 
173
174
  private
174
175
 
@@ -148,8 +148,8 @@ module ReactOnRails
148
148
 
149
149
  Then run: bundle install
150
150
 
151
- No license key is needed to run Pro. Production is free for small organizations, charities, schools, and hospitals;
152
- larger organizations subscribe: https://reactonrails.com/pricing/
151
+ No license key is needed to run Pro. Qualifying production use is free. Other production use
152
+ needs ShakaStack Pro for the whole organization. Free & Pro: https://reactonrails.com/pricing/
153
153
  See the upgrade guide: https://reactonrails.com/docs/pro/upgrading-to-pro/
154
154
  MSG
155
155
  true
@@ -13,6 +13,7 @@ require_relative "spec_helper"
13
13
  require "rspec/rails"
14
14
  require "capybara/rspec"
15
15
  require "capybara/rails"
16
+ require_relative "support/capybara_chrome_reset"
16
17
  Capybara.register_driver :selenium_chrome_headless do |app|
17
18
  options = Selenium::WebDriver::Chrome::Options.new
18
19
  options.add_argument("--headless=new")
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Capybara 3.40.0 ends Selenium ChromeDriver#reset! with
4
+ # execute_cdp("Storage.clearDataForOrigin", origin: "*", storageTypes: "cookies,local_storage")
5
+ # Chrome 158 rejects that origin with "invalid argument: * is not a valid URL", so every
6
+ # example that resets the session errors after it runs and leaves its cookies behind.
7
+ # Upstream: https://github.com/teamcapybara/capybara/issues/2865
8
+ #
9
+ # When Chrome rejects the wildcard, clear every cookie and the localStorage of each origin
10
+ # in the tab's history instead. Older Chrome still takes the original call.
11
+ # Delete this file once the app uses a Capybara release that fixes reset! on Chrome 158.
12
+ # The OSS and Pro dummy apps and the dev_tests generator template each keep a copy of this
13
+ # patch; change all three together.
14
+ require "capybara/selenium/driver"
15
+
16
+ if Gem::Version.new(Capybara::VERSION) <= Gem::Version.new("3.40.0")
17
+ module CapybaraChromeResetWithoutWildcardOrigin
18
+ private
19
+
20
+ def execute_cdp(cmd, params = {})
21
+ super
22
+ rescue Selenium::WebDriver::Error::InvalidArgumentError => e
23
+ raise unless cmd == "Storage.clearDataForOrigin" && params[:origin] == "*" &&
24
+ e.message.include?("is not a valid URL")
25
+
26
+ storage_types = params[:storageTypes].to_s.split(",")
27
+ super("Network.clearBrowserCookies") if storage_types.include?("cookies")
28
+ return unless storage_types.include?("local_storage")
29
+
30
+ visited_origins.each do |origin|
31
+ super("Storage.clearDataForOrigin", { origin:, storageTypes: "local_storage" })
32
+ end
33
+ end
34
+
35
+ def visited_origins
36
+ execute_cdp("Page.getNavigationHistory").fetch("entries", []).filter_map { |entry| origin_of(entry["url"]) }.uniq
37
+ end
38
+
39
+ def origin_of(url)
40
+ uri = URI.parse(url.to_s)
41
+ return unless %w[http https].include?(uri.scheme) && uri.host
42
+
43
+ port = ":#{uri.port}" unless uri.port == uri.default_port
44
+ "#{uri.scheme}://#{uri.host}#{port}"
45
+ rescue URI::InvalidURIError
46
+ nil
47
+ end
48
+ end
49
+
50
+ Capybara::Selenium::Driver::ChromeDriver.prepend(CapybaraChromeResetWithoutWildcardOrigin)
51
+ end
@@ -25,6 +25,13 @@ module ReactOnRails
25
25
  # - Provides a clean API for bin/dev without exposing Rake internals
26
26
  # - Handles hook detection, error handling, and output formatting
27
27
  class PackGenerator
28
+ # Variables Bundler sets or rewrites when it loads, besides the BUNDLE_ and BUNDLER_
29
+ # prefixes. These must not reach the unbundled child, or it would run inside the
30
+ # parent's bundle again.
31
+ BUNDLER_MANAGED_ENV_KEYS = %w[
32
+ PATH MANPATH RUBYOPT RUBYLIB GEM_HOME GEM_PATH RB_USER_INSTALL RUBYGEMS_GEMDEPS
33
+ ].freeze
34
+
28
35
  class << self
29
36
  def generate(verbose: false)
30
37
  # Skip if shakapacker has a precompile hook configured
@@ -152,9 +159,10 @@ module ReactOnRails
152
159
  end
153
160
 
154
161
  def run_via_bundle_exec(silent: false, verbose: false)
155
- # Environment variable is already set in run_pack_generation, but we make it explicit here
156
- # for clarity and to ensure it's passed to the subprocess
157
- env = { "REACT_ON_RAILS_VERBOSE" => verbose ? "true" : "false" }
162
+ # with_unbundled_env resets ENV to Bundler's pre-load snapshot, so pass along every
163
+ # change made since Bundler loaded (e.g. `ENV["FOO"] ||= "1"` in bin/dev).
164
+ # REACT_ON_RAILS_VERBOSE is already set in run_pack_generation; keep it explicit here.
165
+ env = runtime_env_changes.merge("REACT_ON_RAILS_VERBOSE" => verbose ? "true" : "false")
158
166
 
159
167
  # Need to unbundle to prevent Bundler from intercepting our bundle exec call
160
168
  # when already running inside a Bundler context (e.g., from bin/dev)
@@ -171,6 +179,27 @@ module ReactOnRails
171
179
  end
172
180
  end
173
181
 
182
+ # Variables that differ from Bundler's pre-load snapshot, as a `system` env hash.
183
+ # A variable deleted since then maps to nil so the child does not get it back.
184
+ # Bundler's own variables stay out, so the child still runs unbundled.
185
+ def runtime_env_changes
186
+ return {} unless defined?(Bundler) && Bundler.respond_to?(:original_env)
187
+
188
+ original = Bundler.original_env
189
+ (ENV.keys | original.keys).each_with_object({}) do |key, changes|
190
+ next if bundler_managed_env_key?(key)
191
+
192
+ value = ENV.fetch(key, nil)
193
+ changes[key] = value unless value == original[key]
194
+ end
195
+ end
196
+
197
+ # Compare uppercased names: Windows treats them case-insensitively and stores PATH as `Path`.
198
+ def bundler_managed_env_key?(key)
199
+ name = key.upcase
200
+ name.start_with?("BUNDLE_", "BUNDLER_") || BUNDLER_MANAGED_ENV_KEYS.include?(name)
201
+ end
202
+
174
203
  # DRY helper method for Bundler context switching with API compatibility
175
204
  # Supports both new (with_unbundled_env) and legacy (with_clean_env) Bundler APIs
176
205
  def with_unbundled_context(&)
@@ -12,8 +12,8 @@ module ReactOnRails
12
12
  # with_unbundled_env restores the pre-Bundler env snapshot, so any var
13
13
  # set at runtime (e.g. PORT by PortSelector) is lost. We capture them
14
14
  # before entering the block and pass them explicitly to system().
15
- # This follows the same pattern used by Rails' bundle_command (railties),
16
- # Spring's process spawning, and this codebase's own PackGenerator.
15
+ # This follows the same pattern used by Rails' bundle_command (railties) and
16
+ # Spring's process spawning. PackGenerator instead passes every runtime change.
17
17
  #
18
18
  # REACT_ON_RAILS_BASE_PORT and CONDUCTOR_PORT are intentionally excluded:
19
19
  # by the time sub-processes spawn, configure_ports has already derived
@@ -10,6 +10,7 @@ require "timeout"
10
10
  require "uri"
11
11
  require "yaml"
12
12
  require_relative "utils"
13
+ require_relative "exec_js_runtime"
13
14
  require_relative "version"
14
15
  require_relative "config_path_resolver"
15
16
  require_relative "shakapacker_config_helpers"
@@ -73,6 +74,10 @@ module ReactOnRails
73
74
  SERVER_BUNDLE_SOURCE_EXTENSIONS = %w[.js .jsx .ts .tsx .mjs .cjs].freeze
74
75
  CUSTOM_LAUNCHER_INDICATOR_FILES = %w[dev].freeze
75
76
  RAILS_SERVER_COMMAND_REGEX = %r{\b(?:(?:bin/)?rails\s+(?:server|s)|puma|unicorn|rackup|passenger\s+start)\b}
77
+ # As in the shell, "#" starts a comment only at the beginning of a word and outside quotes.
78
+ PROCFILE_TEXT_BEFORE_COMMENT_REGEX = /\A(?:\\.|[^'"#\\]|(?<![\s;&|()])#|'[^']*'|"(?:\\.|[^"\\])*")*/
79
+ # The flag must belong to the same shell command as the binstub, hence no ; & | between them.
80
+ STATIC_WATCHER_COMMAND_REGEX = %r{\bbin/shakapacker(?:-watch)?\s(?:[^;&|]*\s)?(?:--watch|-w)(?![\w-])}
76
81
  TEMPLATE_HTML_COMMENT_PATTERN = /<!--.*?-->/m
77
82
  TEMPLATE_COMMENT_PATTERN = /<!--.*?-->|<%#.*?%>/m
78
83
  ERB_EXPRESSION_PATTERN = /<%(?![#%])={0,2}\s*(?<expression>.*?)-?%>/m
@@ -2032,6 +2037,45 @@ module ReactOnRails
2032
2037
  @shakapacker_manifest_data = nil
2033
2038
  end
2034
2039
 
2040
+ # The runtime React on Rails server rendering uses; it can differ from ExecJS.runtime only
2041
+ # when ExecJS selected Bun.
2042
+ def server_rendering_execjs_runtime_name(execjs_name)
2043
+ return execjs_name unless execjs_name == ReactOnRails::ExecJSRuntime::BUN_NAME
2044
+
2045
+ ReactOnRails::ExecJSRuntime.for_server_rendering.name
2046
+ end
2047
+
2048
+ # The Pro Node Renderer's ExecJS fallback renders through the same pool, so it uses the same runtime.
2049
+ # With the fallback disabled, ExecJS never renders, so there is no runtime to explain or warn about.
2050
+ def report_execjs_fallback_runtime(execjs_name)
2051
+ unless pro_execjs_fallback_enabled?
2052
+ checker.add_info(" ExecJS available as fallback: #{execjs_name}")
2053
+ return
2054
+ end
2055
+
2056
+ runtime_name = server_rendering_execjs_runtime_name(execjs_name)
2057
+ checker.add_info(" ExecJS available as fallback: #{runtime_name}")
2058
+ report_execjs_bun_runtime(execjs_name, runtime_name) if execjs_name == ReactOnRails::ExecJSRuntime::BUN_NAME
2059
+ end
2060
+
2061
+ # Bun cannot evaluate every server bundle (issue #5288). Explains which runtime React on
2062
+ # Rails server rendering uses after ExecJS selected Bun.
2063
+ def report_execjs_bun_runtime(bun_name, runtime_name)
2064
+ if runtime_name == bun_name
2065
+ checker.add_warning(" ⚠️ Server rendering uses #{bun_name}, which fails on some server bundles " \
2066
+ "(\"Expected CommonJS module to have a function wrapper\")")
2067
+ fix = if ENV["EXECJS_RUNTIME"].to_s.empty?
2068
+ "Put node on the PATH of the Rails process; React on Rails then uses it instead of Bun"
2069
+ else
2070
+ "Set EXECJS_RUNTIME=Node"
2071
+ end
2072
+ checker.add_info(" 💡 #{fix}")
2073
+ else
2074
+ checker.add_info(" ℹ️ ExecJS autodetected #{bun_name}; React on Rails server rendering uses " \
2075
+ "#{runtime_name} instead. Set EXECJS_RUNTIME to choose explicitly.")
2076
+ end
2077
+ end
2078
+
2035
2079
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
2036
2080
  def check_server_rendering_engine
2037
2081
  return unless defined?(ReactOnRails)
@@ -2045,7 +2089,7 @@ module ReactOnRails
2045
2089
  if uses_node_renderer
2046
2090
  checker.add_info(" Pro uses NodeRenderer for server rendering")
2047
2091
  if defined?(ExecJS) && ExecJS.runtime
2048
- checker.add_info(" ExecJS available as fallback: #{ExecJS.runtime.name}")
2092
+ report_execjs_fallback_runtime(ExecJS.runtime.name)
2049
2093
  elsif pro_execjs_fallback_enabled?
2050
2094
  checker.add_warning(" ⚠️ ExecJS fallback is enabled but ExecJS is not available")
2051
2095
  checker.add_info(" 💡 Install mini_racer or set renderer_use_fallback_exec_js = false")
@@ -2053,7 +2097,8 @@ module ReactOnRails
2053
2097
  checker.add_info(" ℹ️ ExecJS fallback is disabled (renderer_use_fallback_exec_js = false)")
2054
2098
  end
2055
2099
  elsif defined?(ExecJS)
2056
- runtime_name = ExecJS.runtime.name if ExecJS.runtime
2100
+ execjs_name = ExecJS.runtime.name if ExecJS.runtime
2101
+ runtime_name = server_rendering_execjs_runtime_name(execjs_name)
2057
2102
  if runtime_name
2058
2103
  checker.add_info(" ExecJS Runtime: #{runtime_name}")
2059
2104
 
@@ -2067,6 +2112,7 @@ module ReactOnRails
2067
2112
  else
2068
2113
  checker.add_info(" ℹ️ JavaScript runtime: #{runtime_name}")
2069
2114
  end
2115
+ report_execjs_bun_runtime(execjs_name, runtime_name) if execjs_name == ReactOnRails::ExecJSRuntime::BUN_NAME
2070
2116
  else
2071
2117
  checker.add_warning(" ⚠️ ExecJS runtime not detected")
2072
2118
  end
@@ -2657,7 +2703,7 @@ module ReactOnRails
2657
2703
  end
2658
2704
 
2659
2705
  def active_procfile_lines(content)
2660
- content.each_line.grep_v(/^\s*#/).map { |line| line.sub(/#.*/, "") }
2706
+ content.each_line.grep_v(/^\s*#/).map { |line| line[PROCFILE_TEXT_BEFORE_COMMENT_REGEX] }
2661
2707
  end
2662
2708
 
2663
2709
  def node_renderer_procfile_command(filename)
@@ -3109,7 +3155,9 @@ module ReactOnRails
3109
3155
  def static_procfile_available?
3110
3156
  return false unless File.exist?("Procfile.dev-static-assets")
3111
3157
 
3112
- File.read("Procfile.dev-static-assets").include?("bin/shakapacker --watch")
3158
+ active_procfile_lines(File.read("Procfile.dev-static-assets")).any? do |line|
3159
+ line.match?(STATIC_WATCHER_COMMAND_REGEX)
3160
+ end
3113
3161
  rescue StandardError
3114
3162
  false
3115
3163
  end
@@ -5071,11 +5119,13 @@ module ReactOnRails
5071
5119
  # Each row covers react-on-rails-rsc patches rsc_min_patch..rsc_max_patch (nil = open-ended)
5072
5120
  # on rsc_minor. React must match the Flight line the RSC package bundles:
5073
5121
  # 19.2.x ships Flight 19.2, published 19.3.0 ships Flight 19.2.8 (React on Rails 17.1.0),
5074
- # and 19.3.1+ ships Flight 19.3.0. Only stable react-on-rails-rsc releases are supported.
5122
+ # 19.3.1 ships Flight ~19.3.0, and 19.3.2+ ships the patched Flight ~19.3.1, whose own peers
5123
+ # require React 19.3.1+. Only stable react-on-rails-rsc releases are supported.
5075
5124
  RSC_REACT_SUPPORT_RANGES = [
5076
5125
  { rsc_minor: 2, rsc_min_patch: 1, rsc_max_patch: nil, minor: 2, min_patch: 7 },
5077
5126
  { rsc_minor: 3, rsc_min_patch: 0, rsc_max_patch: 0, minor: 2, min_patch: 8 },
5078
- { rsc_minor: 3, rsc_min_patch: 1, rsc_max_patch: nil, minor: 3, min_patch: 0 }
5127
+ { rsc_minor: 3, rsc_min_patch: 1, rsc_max_patch: 1, minor: 3, min_patch: 0 },
5128
+ { rsc_minor: 3, rsc_min_patch: 2, rsc_max_patch: nil, minor: 3, min_patch: 1 }
5079
5129
  ].freeze
5080
5130
  RSC_SUPPORTED_PACKAGE_MINORS = RSC_REACT_SUPPORT_RANGES.map { |range| range.fetch(:rsc_minor) }.uniq.freeze
5081
5131
  RSC_SUPPORTED_PACKAGE_LINE = RSC_SUPPORTED_PACKAGE_MINORS.map do |minor|
@@ -5098,10 +5148,18 @@ module ReactOnRails
5098
5148
  [19, 2] => "19.2.9",
5099
5149
  [19, 3] => "19.3.1"
5100
5150
  }.freeze
5101
- # Rejected prerelease lines with a known published stable successor: the 19.3.0-rc.4 pin that
5102
- # React on Rails 17.1.0 generated, and the 19.3.1-rc.x soak that 17.2.0.rc.0 and rc.1 admitted.
5103
- # Mirrors prereleaseLinesWithStableSuccessor in rscPeerSupport.ts.
5104
- RSC_PRERELEASE_LINES_WITH_STABLE_SUCCESSOR = [[19, 3, 0], [19, 3, 1]].freeze
5151
+ # Rejected prerelease lines with a known published stable successor, and the React version to
5152
+ # install with it. Each React version is at or above the patched Flight release for its line, so
5153
+ # a fresh install cannot resolve vulnerable react-server-dom-webpack:
5154
+ # - The 19.3.0-rc.4 pin that React on Rails 17.1.0 generated moves to stable 19.3.0, whose Flight
5155
+ # range ~19.2.8 resolves to patched 19.2.9 with React 19.2.9.
5156
+ # - The 19.3.1-rc.x soak that 17.2.0.rc.0 and rc.1 admitted skips stable 19.3.1 (Flight ~19.3.0)
5157
+ # for 19.3.2, which requires patched Flight ~19.3.1.
5158
+ # Mirrors prereleaseSuccessors in rscPeerSupport.ts.
5159
+ RSC_PRERELEASE_STABLE_SUCCESSORS = {
5160
+ [19, 3, 0] => { rsc: "19.3.0", react: "19.2.9" },
5161
+ [19, 3, 1] => { rsc: "19.3.2", react: "19.3.1" }
5162
+ }.freeze
5105
5163
  RSC_MINIMUM_REACT_VERSION = "19.2.7"
5106
5164
  RSC_MINIMUM_REACT_VERSION_TUPLE = RSC_MINIMUM_REACT_VERSION.split(".").map(&:to_i).freeze
5107
5165
  RSC_SUPPORTED_REACT_MAJOR = RSC_MINIMUM_REACT_VERSION_TUPLE.fetch(0)
@@ -5109,6 +5167,12 @@ module ReactOnRails
5109
5167
  RSC_SUPPORTED_REACT_LINE = RSC_REACT_SUPPORT_RANGES.map do |range|
5110
5168
  "#{RSC_SUPPORTED_REACT_MAJOR}.#{range.fetch(:minor)}.x"
5111
5169
  end.uniq.join(" or ")
5170
+ # Numerically later is not enough: Flight 19.3.0 sorts after 19.2.9 and is still vulnerable, so name
5171
+ # the patched floor for each supported React line. Mirrors patchedFlightVersions in rscPeerSupport.ts.
5172
+ RSC_FLIGHT_PATCHED_FLOORS = RSC_SUPPORTED_REACT_MINORS.map do |minor|
5173
+ "#{RSC_FLIGHT_PATCHED_VERSIONS.fetch([RSC_SUPPORTED_REACT_MAJOR, minor])} or later on " \
5174
+ "#{RSC_SUPPORTED_REACT_MAJOR}.#{minor}.x"
5175
+ end.join(", ").freeze
5112
5176
  RSC_DIST_TAGS_TO_CHECK = %w[next rc].freeze
5113
5177
  NPM_VIEW_FETCH_TIMEOUT_MS = 5_000
5114
5178
  NPM_VIEW_FETCH_TIMEOUT_SECONDS = NPM_VIEW_FETCH_TIMEOUT_MS / 1000.0
@@ -5527,21 +5591,19 @@ module ReactOnRails
5527
5591
  with React/React DOM #{react_install}+.
5528
5592
 
5529
5593
  Fix: npm install react@~#{react_install} react-dom@~#{react_install} #{RSC_PACKAGE_NAME}@#{rsc_install} --save-exact
5594
+ Then refresh the lockfile so every #{RSC_FLIGHT_PACKAGE_NAME} copy is patched: #{RSC_FLIGHT_PATCHED_FLOORS}.
5530
5595
  MSG
5531
5596
  false
5532
5597
  end
5533
5598
 
5534
- # Only the lines in RSC_PRERELEASE_LINES_WITH_STABLE_SUCCESSOR have a known published stable
5535
- # successor. Compatibility does not establish publication for other rejected prereleases; use the
5536
- # generator pin for those versions.
5599
+ # Only the lines in RSC_PRERELEASE_STABLE_SUCCESSORS have a known published stable successor.
5600
+ # Compatibility does not establish publication for other rejected prereleases; use the generator
5601
+ # pin for those versions.
5537
5602
  # Returns [rsc_version_to_install, react_version_to_install].
5538
5603
  def rsc_package_floor_install_versions(rsc_version)
5539
- if npm_prerelease(rsc_version).present? &&
5540
- RSC_PRERELEASE_LINES_WITH_STABLE_SUCCESSOR.include?(npm_version_tuple(rsc_version))
5541
- stable_version = npm_version_tuple(rsc_version).join(".")
5542
- if rsc_stable_package_version_supported?(stable_version)
5543
- return [stable_version, recommended_react_install_version_for_rsc_package(stable_version)]
5544
- end
5604
+ if npm_prerelease(rsc_version).present?
5605
+ successor = RSC_PRERELEASE_STABLE_SUCCESSORS[npm_version_tuple(rsc_version)]
5606
+ return [successor.fetch(:rsc), successor.fetch(:react)] if successor
5545
5607
  end
5546
5608
 
5547
5609
  [RSC_PACKAGE_INSTALL_VERSION, recommended_react_install_version_for_rsc_package(RSC_PACKAGE_INSTALL_VERSION)]
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ReactOnRails
4
+ # Chooses the ExecJS runtime React on Rails compiles its server bundle with.
5
+ #
6
+ # ExecJS 2.9+ autodetects Bun ahead of Node.js, and Bun cannot evaluate every server
7
+ # bundle (issue #5288). When ExecJS autodetected Bun and Node.js is installed, React on
8
+ # Rails server rendering uses Node.js instead. Only React on Rails changes: ExecJS.runtime
9
+ # stays as it is for other ExecJS users. An explicit EXECJS_RUNTIME, including
10
+ # EXECJS_RUNTIME=Bun, always wins. ExecJS cannot tell `ExecJS.runtime = ExecJS::Runtimes::Bun`
11
+ # in Ruby code apart from autodetection, so that form also renders with Node.js; use
12
+ # EXECJS_RUNTIME=Bun to force Bun.
13
+ module ExecJSRuntime
14
+ BUN_NAME = "Bun.sh"
15
+
16
+ module_function
17
+
18
+ def for_server_rendering
19
+ runtime = ExecJS.runtime
20
+ return runtime unless autodetected_bun?(runtime) && ExecJS::Runtimes::Node.available?
21
+
22
+ ExecJS::Runtimes::Node
23
+ end
24
+
25
+ def autodetected_bun?(runtime)
26
+ ENV["EXECJS_RUNTIME"].to_s.empty? && bun?(runtime)
27
+ end
28
+
29
+ def bun?(runtime)
30
+ runtime.respond_to?(:name) && runtime.name == BUN_NAME
31
+ end
32
+ end
33
+ end
@@ -38,6 +38,10 @@ module ReactOnRails
38
38
  raise ParseError,
39
39
  "Malformed render result: expected exactly one length-prefixed chunk but found #{results.size}"
40
40
  end
41
+ unless parser.complete?
42
+ raise ParseError, "Malformed render result: incomplete length-prefixed chunk after complete result"
43
+ end
44
+
41
45
  results.first
42
46
  end
43
47
 
@@ -86,6 +90,11 @@ module ReactOnRails
86
90
  )
87
91
  end
88
92
 
93
+ # True when no partial header or content remains buffered.
94
+ def complete?
95
+ @state == :header && @buf.empty?
96
+ end
97
+
89
98
  # True if the parser encountered a protocol error.
90
99
  def error?
91
100
  @state == :error
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "open-uri"
4
4
  require "execjs"
5
+ require "react_on_rails/exec_js_runtime"
5
6
  require "react_on_rails/length_prefixed_parser"
6
7
  require "react_on_rails/lenient_json"
7
8
 
@@ -187,7 +188,7 @@ module ReactOnRails
187
188
  "#{ReactOnRails::Utils.server_bundle_js_file_path}"
188
189
  end
189
190
  end
190
- ExecJS.compile(base_js_code)
191
+ ReactOnRails::ExecJSRuntime.for_server_rendering.compile(base_js_code)
191
192
  rescue StandardError => e
192
193
  msg = "ERROR when compiling base_js_code! " \
193
194
  "See file #{file_name} to " \
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReactOnRails
4
- VERSION = "17.2.1"
4
+ VERSION = "17.3.0.rc.0"
5
5
  end
@@ -1,6 +1,8 @@
1
1
  module ReactOnRails
2
2
  module Dev
3
3
  class PackGenerator
4
+ BUNDLER_MANAGED_ENV_KEYS: Array[String]
5
+
4
6
  def self.generate: (?verbose: bool) -> void
5
7
 
6
8
  private
@@ -14,6 +16,8 @@ module ReactOnRails
14
16
  def self.capture_output: (bool) { () -> bool } -> bool
15
17
  def self.handle_rake_error: (Exception, bool) -> void
16
18
  def self.run_via_bundle_exec: (?silent: bool, ?verbose: bool) -> (bool | nil)
19
+ def self.runtime_env_changes: () -> Hash[String, String?]
20
+ def self.bundler_managed_env_key?: (String) -> bool
17
21
  end
18
22
  end
19
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 17.2.1
4
+ version: 17.3.0.rc.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
@@ -203,6 +203,7 @@ files:
203
203
  - lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb
204
204
  - lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb
205
205
  - lib/generators/react_on_rails/templates/dev_tests/spec/spec_helper.rb
206
+ - lib/generators/react_on_rails/templates/dev_tests/spec/support/capybara_chrome_reset.rb
206
207
  - lib/generators/react_on_rails/templates/dev_tests/spec/system/hello_server_spec.rb
207
208
  - lib/generators/react_on_rails/templates/dev_tests/spec/system/hello_world_spec.rb
208
209
  - lib/generators/react_on_rails/templates/pro/base/config/initializers/react_on_rails_pro.rb.tt
@@ -256,6 +257,7 @@ files:
256
257
  - lib/react_on_rails/doctor_schema.rb
257
258
  - lib/react_on_rails/engine.rb
258
259
  - lib/react_on_rails/error.rb
260
+ - lib/react_on_rails/exec_js_runtime.rb
259
261
  - lib/react_on_rails/font_helper.rb
260
262
  - lib/react_on_rails/git_utils.rb
261
263
  - lib/react_on_rails/helper.rb