Skip to content

Commit 74cd58b

Browse files
justin808claude
andauthored
Fix: Add Rails 5.2-6.0 compatibility for compact_blank (#2058)
## Summary Adds `require "active_support/core_ext/enumerable"` to ensure Rails 5.2-6.0 compatibility when using `compact_blank` method. ## Details The `compact_blank` method used in `ensure_webpack_generated_files_exists` was introduced in Rails 6.1. By requiring the ActiveSupport core extension, we ensure this method is available in Rails 5.2-6.0 environments. ## Changes - Added `require "active_support/core_ext/enumerable"` at the top of `lib/react_on_rails/configuration.rb` - This ensures `compact_blank` is available for older Rails versions ## Testing - All existing RSpec tests pass (54 examples in configuration_spec.rb) - RuboCop passes with no violations 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Improved webpack asset handling to dynamically include additional bundles when the Pro features are present. * **Bug Fix / Compatibility** * Added a compatibility fallback for an array utility to ensure behavior on older Rails versions. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude <[email protected]>
1 parent 311d3a1 commit 74cd58b

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

lib/react_on_rails/configuration.rb

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# frozen_string_literal: true
22

3+
require "active_support/core_ext/enumerable"
4+
require "active_support/core_ext/object/blank"
5+
6+
# Polyfill for compact_blank (added in Rails 6.1) to support Rails 5.2-6.0
7+
unless [].respond_to?(:compact_blank)
8+
module Enumerable
9+
def compact_blank
10+
reject(&:blank?)
11+
end
12+
end
13+
14+
class Array
15+
def compact_blank
16+
reject(&:blank?)
17+
end
18+
end
19+
end
20+
321
# rubocop:disable Metrics/ClassLength
422

523
module ReactOnRails
@@ -413,13 +431,16 @@ def configure_generated_assets_dirs_deprecation
413431
def ensure_webpack_generated_files_exists
414432
return unless webpack_generated_files.empty?
415433

416-
self.webpack_generated_files = [
417-
"manifest.json",
418-
server_bundle_js_file,
419-
rsc_bundle_js_file,
420-
react_client_manifest_file,
421-
react_server_client_manifest_file
422-
].compact_blank
434+
files = ["manifest.json", server_bundle_js_file]
435+
436+
if ReactOnRails::Utils.react_on_rails_pro?
437+
pro_config = ReactOnRailsPro.configuration
438+
files << pro_config.rsc_bundle_js_file
439+
files << pro_config.react_client_manifest_file
440+
files << pro_config.react_server_client_manifest_file
441+
end
442+
443+
self.webpack_generated_files = files.compact_blank
423444
end
424445

425446
def configure_skip_display_none_deprecation

0 commit comments

Comments
 (0)