Fix RSpec helper optimization gap with private SSR directories#1838
Fix RSpec helper optimization gap with private SSR directories#1838
Conversation
|
Warning Rate limit exceeded@justin808 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 24 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
WalkthroughReworks Configuration#ensure_webpack_generated_files_exists to compute a complete required-files list (including optional RSC and React manifests when configured) and then either initialize Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller as Test/Runtime
participant Config as Configuration
Note over Caller,Config: Populate webpack_generated_files
Caller->>Config: ensure_webpack_generated_files_exists()
Config->>Config: require active_support enumerable
Config->>Config: Build all_required_files (manifest, server bundle, optionally rsc & react manifests)
alt webpack_generated_files is empty
Config->>Config: Set webpack_generated_files = all_required_files.compact_blank()
else webpack_generated_files exists
Config->>Config: missing = all_required_files - webpack_generated_files
alt missing not empty
Config->>Config: Append missing entries (no duplicates)
else
Config->>Config: No change
end
end
Config-->>Caller: webpack_generated_files updated/unchanged
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Potential hotspots:
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Code Review for PR #1838: Fix RSpec helper optimization gap with private SSR directoriesSummaryThis PR successfully addresses a critical gap in the RSpec helper optimization that emerged after PR #1798's security improvements. The fix ensures server bundles in private directories are properly monitored during test runs, preventing tests from running with stale server-side code. ✅ Strengths
🎯 Code QualityThe implementation follows Ruby best practices:
✅ Security ConsiderationsThe fix properly maintains the security improvements from PR #1798:
📊 Performance
🔍 Potential Enhancements (Optional for future PRs)
✅ Testing VerificationThe test suite thoroughly validates:
🎖️ Overall AssessmentAPPROVED - This is a well-crafted fix that elegantly solves the optimization gap without introducing complexity or breaking changes. The comprehensive test coverage ensures reliability, and the implementation maintains the security improvements from PR #1798. The PR demonstrates excellent engineering practices:
Great work on identifying and fixing this subtle but important issue! 🚀 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
lib/react_on_rails/configuration.rb (1)
323-336: Make list-building nil-safe and dedupe via set-union; also simplify control flowCurrent code raises if
webpack_generated_filesisnil, and duplicates persist if pre-seeded by users. Prefer treatingnilas empty, removing duplicates, and appending missing in one step.Apply:
- all_required_files = [ - "manifest.json", - server_bundle_js_file, - rsc_bundle_js_file, - react_client_manifest_file, - react_server_client_manifest_file - ].compact_blank - - if webpack_generated_files.empty? - self.webpack_generated_files = all_required_files - else - missing_files = all_required_files.reject { |file| webpack_generated_files.include?(file) } - self.webpack_generated_files += missing_files if missing_files.any? - end + required = [ + "manifest.json", + server_bundle_js_file, + rsc_bundle_js_file, + react_client_manifest_file, + react_server_client_manifest_file + ].compact_blank + + current = Array(webpack_generated_files) + self.webpack_generated_files = + if current.blank? + required + else + current | required + endspec/react_on_rails/configuration_spec.rb (1)
528-673: Strong coverage of required-file population; add two edge testsThe scenarios look solid and align with the new behavior. Consider adding:
- A case where
webpack_generated_filesisnil(ensure nil-safety).- A case where
webpack_generated_filescontains duplicates (ensure de-dup).Example additions:
+ context "when webpack_generated_files is nil" do + it "treats nil as empty and populates required files" do + config.webpack_generated_files = nil + config.server_bundle_js_file = "server-bundle.js" + config.send(:ensure_webpack_generated_files_exists) + expect(config.webpack_generated_files).to eq(%w[ + manifest.json + server-bundle.js + react-client-manifest.json + react-server-client-manifest.json + ]) + end + end + + context "when webpack_generated_files has duplicates" do + it "does not keep duplicate entries after ensuring required files" do + config.webpack_generated_files = %w[manifest.json manifest.json server-bundle.js] + config.send(:ensure_webpack_generated_files_exists) + expect(config.webpack_generated_files.count("manifest.json")).to eq(1) + end + end
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
lib/react_on_rails/configuration.rb(1 hunks)spec/react_on_rails/configuration_spec.rb(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
{Gemfile,Rakefile,config.ru,**/*.{rb,rake,gemspec,ru}}
📄 CodeRabbit inference engine (CLAUDE.md)
{Gemfile,Rakefile,config.ru,**/*.{rb,rake,gemspec,ru}}: All Ruby code must pass RuboCop with zero offenses before commit/push
RuboCop is the sole authority for Ruby file formatting; never manually format Ruby files
Files:
spec/react_on_rails/configuration_spec.rblib/react_on_rails/configuration.rb
🧠 Learnings (2)
📓 Common learnings
Learnt from: justin808
PR: shakacode/react_on_rails#1770
File: lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx:2-2
Timestamp: 2025-09-16T08:01:11.146Z
Learning: React on Rails uses webpack CSS Modules configuration with namedExports: true, which requires the import syntax `import * as style from './file.module.css'` rather than the default export pattern. This configuration enables better tree shaking and bundle size optimization for CSS modules.
📚 Learning: 2025-09-16T08:01:11.146Z
Learnt from: justin808
PR: shakacode/react_on_rails#1770
File: lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx:2-2
Timestamp: 2025-09-16T08:01:11.146Z
Learning: React on Rails uses webpack CSS Modules configuration with namedExports: true, which requires the import syntax `import * as style from './file.module.css'` rather than the default export pattern. This configuration enables better tree shaking and bundle size optimization for CSS modules.
Applied to files:
lib/react_on_rails/configuration.rb
🧬 Code graph analysis (1)
spec/react_on_rails/configuration_spec.rb (1)
lib/react_on_rails/test_helper/webpack_assets_status_checker.rb (1)
include(11-101)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: rspec-package-tests (3.2, latest)
- GitHub Check: rspec-package-tests (3.4, latest)
- GitHub Check: rspec-package-tests (3.2, minimum)
- GitHub Check: rspec-package-tests (3.4, minimum)
- GitHub Check: claude-review
- GitHub Check: build
- GitHub Check: build-dummy-app-webpack-test-bundles (3.2, 20)
- GitHub Check: build-and-test
|
@ihabadham I'm finishing this one up. |
Code Review - PR #1838Thank you for working on this important optimization fix! The PR addresses a real gap in server bundle staleness detection. However, I've identified a critical bug that will cause the code to fail. 🔴 Critical Issue: Undefined MethodsLocation: The rsc_bundle_js_file,
react_client_manifest_file,
react_server_client_manifest_fileThese methods are only defined in Impact: This will cause a Test Evidence: The tests in config.rsc_bundle_js_file = nil
config.react_client_manifest_file = "react-client-manifest.json"
config.react_server_client_manifest_file = "react-server-client-manifest.json"This works in tests because RSpec allows setting arbitrary attributes, but will fail in production. Recommended FixAdd these attributes to the open-source # In lib/react_on_rails/configuration.rb
class Configuration
attr_accessor :node_modules_location, :server_bundle_js_file, :prerender, :replay_console,
# ... existing attributes ...
:server_bundle_output_path, :enforce_private_server_bundles,
:rsc_bundle_js_file, :react_client_manifest_file, # ADD THESE
:react_server_client_manifest_file # ADD THESEAnd initialize them in the ✅ Positive Aspects
📋 Other ObservationsCode Quality
Testing
Documentation
🔧 Required Changes Before Merge
🔒 Security & Performance
SummaryThis is a valuable fix for an important optimization gap, but requires the critical bug fix mentioned above before it can be safely merged. Once the missing attributes are added to the open-source Configuration class, this will be ready to go. Let me know if you need any clarification on the required changes! 🤖 Generated with Claude Code |
Code Review - PR #1838Thank you for this PR addressing the RSpec helper optimization gap! The core idea is excellent and the problem identification is spot-on. However, I've identified a critical bug that will cause failures in the open-source version. 🚨 Critical Issue: NoMethodError in Open-Source VersionProblemThe implementation at lib/react_on_rails/configuration.rb:366-368 calls: public_send(:rsc_bundle_js_file),
public_send(:react_client_manifest_file),
public_send(:react_server_client_manifest_file)However, these methods do not exist in the open-source Impact
EvidenceCheck lib/react_on_rails/configuration.rb:57-69 - the
💡 Recommended SolutionsOption 1: Add Conditional Logic (Preferred)Only call Pro methods when Pro is available: def ensure_webpack_generated_files_exists
all_required_files = ["manifest.json", server_bundle_js_file]
# Add Pro files if Pro is available
if ReactOnRails::Utils.react_on_rails_pro?
pro_config = ReactOnRailsPro.configuration
all_required_files += [
pro_config.rsc_bundle_js_file,
pro_config.react_client_manifest_file,
pro_config.react_server_client_manifest_file
]
end
all_required_files.compact_blank!
if webpack_generated_files.empty?
self.webpack_generated_files = all_required_files
else
missing_files = all_required_files.reject { |file| webpack_generated_files.include?(file) }
self.webpack_generated_files += missing_files if missing_files.any?
end
endOption 2: Use
|
Code Review: PR #1838 - Fix RSpec helper optimization gap with private SSR directoriesSummaryThis PR addresses a critical optimization gap where server bundle staleness was not detected when using private SSR directories, leading to tests running with stale server-side code. The fix is well-designed, thoroughly tested, and production-ready. ✅ Strengths1. Excellent Problem Analysis
2. Smart Implementation ApproachThe "Smart Auto-Inclusion" logic is elegant:
3. Comprehensive Test Coverage ⭐The test suite covers all critical scenarios:
4. Backward Compatibility
5. Ruby Compatibility HandlingCommits 3-5 show excellent attention to cross-version compatibility:
🔍 Code Quality ObservationsConfiguration.rb (lines 362-377)Positive:
Minor Suggestion: # Check for Pro features that may not exist in open-source version
(rsc_bundle_js_file if respond_to?(:rsc_bundle_js_file)),Test Coverage (lines 554-671)Excellent:
🛡️ Security & PerformanceSecurity✅ No security concerns identified
Performance✅ Minimal performance impact
🧪 Testing RecommendationsAlready Covered ✅
Additional Testing (Optional)Consider adding integration tests to verify:
Example test scenario: # In RSpec integration test
it "detects server bundle staleness with default config" do
# 1. Configure with default manifest.json only
# 2. Modify server bundle file timestamp
# 3. Verify RSpec helper triggers rebuild
end📝 DocumentationCurrent State
Recommendations
🐛 Potential IssuesIssue 1: Test Setup AssumptionsLocation: The test setup assumes Pro methods exist: config.rsc_bundle_js_file = nil
config.react_client_manifest_file = "react-client-manifest.json"Why this might fail: When CI merges this PR against master (which doesn't have Pro features yet), these attribute assignments will raise Suggested Fix: before do
config.server_bundle_js_file = "server-bundle.js"
# Only set Pro attributes if they exist
if config.respond_to?(:rsc_bundle_js_file=)
config.rsc_bundle_js_file = nil
config.react_client_manifest_file = "react-client-manifest.json"
config.react_server_client_manifest_file = "react-server-client-manifest.json"
end
endIssue 2: Test Expectations May Need AdjustmentLocation: Multiple test expectations Tests expect Pro manifest files to be included: expect(config.webpack_generated_files).to eq(%w[
manifest.json
server-bundle.js
react-client-manifest.json # Won't exist in open-source
react-server-client-manifest.json # Won't exist in open-source
])Suggested Fix: Make expectations conditional on Pro features: expected_files = %w[manifest.json server-bundle.js]
if config.respond_to?(:react_client_manifest_file)
expected_files += %w[react-client-manifest.json react-server-client-manifest.json]
end
expect(config.webpack_generated_files).to eq(expected_files)🎯 Final VerdictStatus: Approve with Minor Suggestions ✅ Required Before Merge
Recommended (Non-blocking)
💡 AcknowledgmentsExcellent work on:
The evolution through commits 1-5 shows great attention to cross-version compatibility issues - this is exactly the kind of defensive programming that prevents production issues. Overall Assessment: This is a high-quality fix that solves a real problem with minimal risk. The test coverage is exemplary. Address the test setup issue and this is ready to merge! 🚀 |
a31b97f to
6941fb1
Compare
This fix addresses an issue where the server bundle file wasn't being automatically added to webpack_generated_files when users had manually configured the array (e.g., setting it to just ["manifest.json"]). Previously, ensure_webpack_generated_files_exists only populated the array when it was empty. This meant that if users specified any files, critical files like the server bundle would be missing from monitoring. Changes: - Modified ensure_webpack_generated_files_exists to add missing critical files even when webpack_generated_files is not empty - Added comprehensive test coverage for various scenarios including: * Empty webpack_generated_files array * Partial configuration with only manifest.json * Custom files preservation * Nil/empty server bundle handling * Cross-directory file monitoring - Fixed Pro license test mock to properly stub ReactOnRailsPro.configuration This ensures that RSpec helper optimizations work correctly when server bundles are in private directories separate from public assets. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
6941fb1 to
8ad152e
Compare
Summary
Fixes an optimization gap in the RSpec helper where server bundle staleness was not detected when using private SSR directories (introduced in PR #1798).
webpack_generated_files: ['manifest.json']configuration only monitored client assets, missing server bundle changes in privatessr-generated/directoryensure_webpack_generated_files_existsto automatically include server bundles and other critical files in monitoring listRoot Cause
PR #1798 moved server bundles to private directories for security, but the RSpec helper optimization continued monitoring only
manifest.jsonby default. This created a gap where:ssr-generated/server-bundle.jspublic/packs-test/manifest.jsonWhy this worked before: Prior to PR #1798, both client and server bundles were co-located in the same
public/packs/directory, so the RSpec helper's fallback logic would detect server bundle staleness even when only monitoringmanifest.json.Fix Details
Before:
After:
Testing
Test plan
public/, server inssr-generated/)Fixes #1822
🤖 Generated with Claude Code
This change is
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.