Skip to content
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a3c3391
Fix Shakapacker version requirement from 8.2.0 to 8.0.0 for basic com…
justin808 Sep 21, 2025
233b789
Simplify PackerUtils by removing legacy Webpacker compatibility code
justin808 Sep 21, 2025
339451a
Apply auto-fix corrections from RuboCop
justin808 Sep 21, 2025
0a566cd
Remove unnecessary packer_type template variable
justin808 Sep 21, 2025
759e360
Simplify autobundling requirements check using feature-based method
justin808 Sep 21, 2025
07e68db
Remove unused packer_name variable
justin808 Sep 21, 2025
7fdc7b4
Remove unnecessary Packer alias
justin808 Sep 21, 2025
30e0e6d
Fix mock objects in packer_utils_spec
justin808 Sep 21, 2025
37e54a1
Fix failing configuration tests by adding packer mocks
justin808 Sep 21, 2025
68f4baf
Fix CI failure by not setting default generated_assets_dir with Shaka…
justin808 Sep 22, 2025
1e2f03c
Fix failing tests by properly mocking Shakapacker initialization
justin808 Sep 22, 2025
c5ae0f9
Remove legacy 'without packer' test scenarios and using_packer? refer…
justin808 Sep 23, 2025
35784e9
Trigger CI to test fixes
justin808 Sep 23, 2025
bc73e88
Trigger CI after RuboCop fixes
justin808 Sep 23, 2025
a575302
Address version requirement review comments
justin808 Sep 23, 2025
943b843
Final fix for CI: String constants and RuboCop disables
justin808 Sep 23, 2025
00d2670
Add comprehensive improvements based on feedback
justin808 Sep 23, 2025
b672d92
Improve warning message clarity and remove unnecessary variable
justin808 Sep 23, 2025
27eda87
Add memoization for performance optimization
justin808 Sep 23, 2025
70b4c7d
Remove redundant shakapacker_gem_available? checks
justin808 Sep 23, 2025
5b3e5ff
Simplify supports_auto_registration? method
justin808 Sep 23, 2025
9db5190
Add performance optimizations and validation tests
justin808 Sep 23, 2025
67210ef
Fix thread safety and simplify Shakapacker packer memoization
justin808 Sep 23, 2025
da9420e
Fix error message to match test expectation
justin808 Sep 23, 2025
e038121
Improve method naming and warning message clarity
justin808 Sep 23, 2025
8d03cc6
Remove PackerUtils.packer method entirely and use Shakapacker directly
justin808 Sep 23, 2025
5d865c0
Fix remaining test failures after removing PackerUtils.packer method
justin808 Sep 23, 2025
437cec8
Trigger CI re-run after RuboCop auto-fix
justin808 Sep 23, 2025
4b932ad
Fix documentation to use bundle exec rubocop consistently
justin808 Sep 23, 2025
9ca52d1
Update CHANGELOG.md for PackerUtils.packer abstraction removal
justin808 Sep 23, 2025
8a33f7d
Add author attribution to CHANGELOG.md entry
justin808 Sep 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Changes since the last non-beta release.
#### Bug Fixes

- **Doctor rake task**: Fixed LoadError in `rake react_on_rails:doctor` when using packaged gem. The task was trying to require excluded `rakelib/task_helpers` file. [PR 1795](https://github.com/shakacode/react_on_rails/pull/1795)
- **Shakapacker version requirements**: Fixed inconsistent version requirements between basic pack generation (6.5.1+) and advanced auto-registration features (7.0.0+). Added backward compatibility for users on Shakapacker 6.5.1-6.9.x while providing clear upgrade guidance for advanced features. Added new constants `MINIMUM_SHAKAPACKER_VERSION_FOR_AUTO_REGISTRATION` and improved version checking performance with caching. [PR 1798](https://github.com/shakacode/react_on_rails/pull/1798)

### [16.0.1-rc.0] - 2025-09-19

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
react_on_rails (16.0.1.rc.0)
react_on_rails (16.0.1.rc.2)
addressable
connection_pool
execjs (~> 2.5)
Expand Down
2 changes: 1 addition & 1 deletion docs/contributor-info/linters.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ If you haven't tried the autofix options for `eslint` and `rubocop`, you're seri
2. **Rubocop:** Be sure to be in the correct directory where you have Ruby files, usually the top level of your Rails project.

```bash
rubocop -a
bundle exec rubocop -a
```

3. **ESLint:** Be sure to be in the correct directory where you have JS files.
Expand Down
15 changes: 15 additions & 0 deletions docs/guides/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ ReactOnRails.configure do |config|
# `render_component` and `render_component_hash` view helper methods can
# auto-load the bundle for the generated component, to avoid having to specify the
# bundle manually for each view with the component.
#
# SHAKAPACKER VERSION REQUIREMENTS:
# - Basic pack generation: Shakapacker 6.5.1+
# - Advanced auto-registration with nested entries: Shakapacker 7.0.0+
# - Async loading support: Shakapacker 8.2.0+
#
# Feature Compatibility Matrix:
# | Shakapacker Version | Basic Pack Generation | Auto-Registration | Nested Entries | Async Loading |
# |-------------------|----------------------|-------------------|----------------|---------------|
# | 6.5.1 - 6.9.x | ✅ Yes | ❌ No | ❌ No | ❌ No |
# | 7.0.0 - 8.1.x | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No |
# | 8.2.0+ | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
#
################################################################################
# components_subdirectory is the name of the subdirectory matched to detect and register components automatically
# The default is nil. You can enable the feature by updating it in the next line.
Expand All @@ -205,6 +218,8 @@ ReactOnRails.configure do |config|
# Default is false.
# The default can be overridden as an option in calls to view helpers
# `render_component` and `render_component_hash`. You may set to true to change the default to auto loading.
# NOTE: Requires Shakapacker 6.5.1+ for basic functionality, 7.0.0+ for full auto-registration features.
# See version requirements matrix above for complete feature compatibility.
config.auto_load_bundle = false

# Default is false
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/react_on_rails/base_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def copy_base_files
base_templates = %w[config/initializers/react_on_rails.rb]
base_files.each { |file| copy_file("#{base_path}#{file}", file) }
base_templates.each do |file|
template("#{base_path}/#{file}.tt", file, { packer_type: ReactOnRails::PackerUtils.packer_type })
template("#{base_path}/#{file}.tt", file)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ ReactOnRails.configure do |config|
# to automatically refresh your webpack assets on every test run.
#
# Alternately, you can remove the `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`
# and set the config/<%= config[:packer_type] %>.yml option for test to true.
config.build_test_command = "RAILS_ENV=test bin/<%= config[:packer_type] %>"
# and set the config/shakapacker.yml option for test to true.
config.build_test_command = "RAILS_ENV=test bin/shakapacker"

################################################################################
################################################################################
Expand Down
83 changes: 36 additions & 47 deletions lib/react_on_rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def validate_generated_component_packs_loading_strategy
1. Use :sync or :defer loading strategy instead of :async
2. Upgrade to Shakapacker v8.2.0 or above to enable async script loading
MSG
if PackerUtils.shakapacker_version_requirement_met?("8.2.0")
if PackerUtils.supports_async_loading?
self.generated_component_packs_loading_strategy ||= :async
elsif generated_component_packs_loading_strategy.nil?
Rails.logger.warn("**WARNING** #{msg}")
Expand All @@ -198,12 +198,19 @@ def check_autobundling_requirements
raise_missing_components_subdirectory if auto_load_bundle && !components_subdirectory.present?
return unless components_subdirectory.present?

ReactOnRails::PackerUtils.raise_shakapacker_not_installed unless ReactOnRails::PackerUtils.using_packer?
ReactOnRails::PackerUtils.raise_shakapacker_version_incompatible_for_autobundling unless
ReactOnRails::PackerUtils.shakapacker_version_requirement_met?(
ReactOnRails::PacksGenerator::MINIMUM_SHAKAPACKER_VERSION
)
ReactOnRails::PackerUtils.raise_nested_entries_disabled unless ReactOnRails::PackerUtils.nested_entries?
# Check basic pack generation support for auto_load_bundle
ReactOnRails::PackerUtils.raise_shakapacker_version_incompatible_for_basic_pack_generation unless
ReactOnRails::PackerUtils.supports_basic_pack_generation?

# Additional checks for advanced features requiring nested entries
if ReactOnRails::PackerUtils.supports_autobundling?
ReactOnRails::PackerUtils.raise_nested_entries_disabled unless ReactOnRails::PackerUtils.nested_entries?
else
# Warn users about missing advanced features but don't block basic functionality
min_version = ReactOnRails::PacksGenerator::MINIMUM_SHAKAPACKER_VERSION_FOR_AUTO_REGISTRATION
Rails.logger.warn("React on Rails: Basic pack generation enabled. " \
"Upgrade to Shakapacker #{min_version}+ for advanced auto-registration features.")
end
end

def adjust_precompile_task
Expand All @@ -221,8 +228,8 @@ def adjust_precompile_task
# We set it very big so that it is not used, and then clean just
# removes files older than 1 hour.
versions = 100_000
puts "Invoking task #{ReactOnRails::PackerUtils.packer_type}:clean from React on Rails"
Rake::Task["#{ReactOnRails::PackerUtils.packer_type}:clean"].invoke(versions)
puts "Invoking task shakapacker:clean from React on Rails"
Rake::Task["shakapacker:clean"].invoke(versions)
}

if Rake::Task.task_defined?("assets:precompile")
Expand All @@ -237,23 +244,21 @@ def adjust_precompile_task
end

def error_if_using_packer_and_generated_assets_dir_not_match_public_output_path
return unless ReactOnRails::PackerUtils.using_packer?

return if generated_assets_dir.blank?

packer_public_output_path = ReactOnRails::PackerUtils.packer_public_output_path

if File.expand_path(generated_assets_dir) == packer_public_output_path.to_s
Rails.logger.warn("You specified generated_assets_dir in `config/initializers/react_on_rails.rb` " \
"with #{ReactOnRails::PackerUtils.packer_type}. " \
"with shakapacker. " \
"Remove this line from your configuration file.")
else
msg = <<~MSG
Error configuring /config/initializers/react_on_rails.rb: You are using #{ReactOnRails::PackerUtils.packer_type}
and your specified value for generated_assets_dir = #{generated_assets_dir}
that does not match the value for public_output_path specified in
#{ReactOnRails::PackerUtils.packer_type}.yml = #{packer_public_output_path}. You should remove the configuration
value for "generated_assets_dir" from your config/initializers/react_on_rails.rb file.
Configuration mismatch in config/initializers/react_on_rails.rb:

Your generated_assets_dir setting (#{generated_assets_dir}) does not match the value for public_output_path (#{packer_public_output_path}).

Remove the generated_assets_dir configuration and let Shakapacker manage the output path.
MSG
raise ReactOnRails::Error, msg
end
Expand All @@ -272,36 +277,22 @@ def check_server_render_method_is_only_execjs
end

def ensure_generated_assets_dir_present
return if generated_assets_dir.present? || ReactOnRails::PackerUtils.using_packer?
return if generated_assets_dir.present?

self.generated_assets_dir = DEFAULT_GENERATED_ASSETS_DIR
Rails.logger.warn "ReactOnRails: Set generated_assets_dir to default: #{DEFAULT_GENERATED_ASSETS_DIR}"
# When using Shakapacker, don't set a default generated_assets_dir since
# Shakapacker manages its own public_output_path configuration
# This prevents configuration mismatches between ReactOnRails and Shakapacker
Rails.logger.warn "ReactOnRails: No generated_assets_dir specified, using Shakapacker public_output_path"
end

def configure_generated_assets_dirs_deprecation
return if generated_assets_dirs.blank?

if ReactOnRails::PackerUtils.using_packer?
packer_public_output_path = ReactOnRails::PackerUtils.packer_public_output_path
# rubocop:disable Layout/LineLength
packer_name = ReactOnRails::PackerUtils.packer_type&.upcase_first

Rails.logger.warn "Error configuring config/initializers/react_on_rails. Define neither the generated_assets_dirs nor " \
"the generated_assets_dir when using #{packer_name}. This is defined by " \
"public_output_path specified in #{ReactOnRails::PackerUtils.packer_type}.yml = #{packer_public_output_path}."
# rubocop:enable Layout/LineLength
return
end

Rails.logger.warn "[DEPRECATION] ReactOnRails: Use config.generated_assets_dir rather than " \
"generated_assets_dirs"
if generated_assets_dir.blank?
self.generated_assets_dir = generated_assets_dirs
else
Rails.logger.warn "[DEPRECATION] ReactOnRails. You have both generated_assets_dirs and " \
"generated_assets_dir defined. Define ONLY generated_assets_dir if NOT using Shakapacker " \
"and define neither if using Webpacker"
end
packer_public_output_path = ReactOnRails::PackerUtils.packer_public_output_path
Rails.logger.warn "You specified generated_assets_dirs in `config/initializers/react_on_rails.rb` " \
"with Shakapacker. Remove this configuration as the output path is automatically " \
"determined by `public_output_path` in shakapacker.yml " \
"(currently: #{packer_public_output_path})."
end

def ensure_webpack_generated_files_exists
Expand Down Expand Up @@ -333,17 +324,15 @@ def raise_missing_components_subdirectory
end

def compile_command_conflict_message
packer_name = ReactOnRails::PackerUtils.packer_type.upcase_first
packer_type = ReactOnRails::PackerUtils.packer_type
<<~MSG

React on Rails and #{packer_name} error in configuration!
React on Rails and Shakapacker error in configuration!
In order to use config/react_on_rails.rb config.build_production_command,
you must edit config/#{packer_type}.yml to include this value in the default configuration:
'#{packer_type}_precompile: false'
you must edit config/shakapacker.yml to include this value in the default configuration:
'shakapacker_precompile: false'

Alternatively, remove the config/react_on_rails.rb config.build_production_command and the
default bin/#{packer_type} script will be used for assets:precompile.
default bin/shakapacker script will be used for assets:precompile.

MSG
end
Expand Down
Loading
Loading