Add private_output_path configuration for SSR bundles#592
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 17 minutes and 21 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 (5)
WalkthroughAdds a commented private_output_path option to the install config, implements Configuration#private_output_path to resolve that path against root, and adds a spec verifying the resolved path. Documentation and changelog entries were updated. Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as Developer / Config file
participant App as Shakapacker::Configuration
participant FS as Filesystem (root_path)
Dev->>App: (option) set :private_output_path = "ssr-generated"
App->>FS: root_path.join("ssr-generated")
FS-->>App: "/path/to/project/ssr-generated"
App-->>Dev: returns private_output_path (Pathname)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
lib/install/config/shakapacker.yml (1)
32-36: Set an explicit default for private_output_path to avoid nil errors.Comment-only docs claim a default of tmp/shakapacker, but no default is actually set. This leads to nil being joined in Configuration#private_output_path.
Apply this diff to define the default and keep the example:
- # Location for private output, defaults to tmp/shakapacker - # This setting is for generating bundles that are only used in server-side rendering - # and should not be served publicly (alternative to public_output_path) - # private_output_path: ssr-generated + # Location for private output; default is tmp/shakapacker + # This setting is for generating bundles that are only used in server-side rendering + # and should not be served publicly (alternative to public_output_path) + private_output_path: tmp/shakapacker + # Example custom value: + # private_output_path: ssr-generated
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
lib/install/config/shakapacker.yml(1 hunks)lib/shakapacker/configuration.rb(1 hunks)spec/shakapacker/configuration_spec.rb(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2024-10-09T10:50:16.512Z
Learnt from: marvinthepa
PR: shakacode/shakapacker#520
File: spec/shakapacker/utils_manager_spec.rb:104-116
Timestamp: 2024-10-09T10:50:16.512Z
Learning: In `spec/shakapacker/utils_manager_spec.rb`, `error_unless_package_manager_is_obvious` is not a test method, so extracting into a shared context may not be helpful.
Applied to files:
spec/shakapacker/configuration_spec.rb
📚 Learning: 2024-10-09T10:47:17.620Z
Learnt from: marvinthepa
PR: shakacode/shakapacker#520
File: spec/shakapacker/utils_manager_spec.rb:68-89
Timestamp: 2024-10-09T10:47:17.620Z
Learning: In `spec/shakapacker/utils_manager_spec.rb`, the code within the context `"when lockfile is in Rails.root, but pwd is different"` is not duplicated for each package manager.
Applied to files:
spec/shakapacker/configuration_spec.rb
🧬 Code graph analysis (1)
spec/shakapacker/configuration_spec.rb (1)
lib/shakapacker/configuration.rb (1)
private_output_path(71-73)
🪛 GitHub Actions: Ruby based checks
lib/shakapacker/configuration.rb
[error] 72-72: private_output_path method encountered nil while converting to String
spec/shakapacker/configuration_spec.rb
[error] 60-60: RSpec failure in Shakapacker::Configuration: TypeError - no implicit conversion of nil into String
⏰ 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). (21)
- GitHub Check: Generator specs (ubuntu-latest, 3.3, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.4, gemfiles/Gemfile-rails.8.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.3, gemfiles/Gemfile-rails.8.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.4, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.2, gemfiles/Gemfile-rails.7.2.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.4, gemfiles/Gemfile-rails.7.2.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.3, gemfiles/Gemfile-rails.7.2.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.0, gemfiles/Gemfile-rails.6.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.1, gemfiles/Gemfile-rails.7.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.1, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.0, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.2, gemfiles/Gemfile-rails.8.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.0, gemfiles/Gemfile-rails.7.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 2.7, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 2.7, gemfiles/Gemfile-rails.7.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.1, gemfiles/Gemfile-rails.7.2.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.1, gemfiles/Gemfile-rails.6.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 2.7, gemfiles/Gemfile-rails.6.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.0, gemfiles/Gemfile-rails.6.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 2.7, gemfiles/Gemfile-rails.6.1.x)
- GitHub Check: Testing (ubuntu-latest, 3.1, gemfiles/Gemfile-rails.6.1.x)
| def private_output_path | ||
| root_path.join(fetch(:private_output_path)) | ||
| end |
There was a problem hiding this comment.
Fix nil handling in private_output_path (pipeline failure).
fetch(:private_output_path) can be nil (no default set), causing TypeError when joining.
Apply this diff to fall back to cache_path:
- def private_output_path
- root_path.join(fetch(:private_output_path))
- end
+ def private_output_path
+ root_path.join(fetch(:private_output_path) || fetch(:cache_path))
+ end📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def private_output_path | |
| root_path.join(fetch(:private_output_path)) | |
| end | |
| def private_output_path | |
| root_path.join(fetch(:private_output_path) || fetch(:cache_path)) | |
| end |
🧰 Tools
🪛 GitHub Actions: Ruby based checks
[error] 72-72: private_output_path method encountered nil while converting to String
🤖 Prompt for AI Agents
In lib/shakapacker/configuration.rb around lines 71 to 73, private_output_path
currently calls root_path.join(fetch(:private_output_path)) which raises a
TypeError when fetch(:private_output_path) is nil; update the method to fall
back to cache_path when the fetched value is nil by using the fetched value if
present, otherwise using cache_path before joining with root_path.
| it "#private_output_path returns correct path" do | ||
| private_output_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/ssr-generated").to_s | ||
|
|
||
| expect(config.private_output_path.to_s).to eq private_output_path | ||
| end |
There was a problem hiding this comment.
Align test with actual default or set a fixture.
Current test expects ssr-generated but config doesn’t set it, causing failure. Either change the expectation to the documented default (tmp/shakapacker), or set private_output_path in the test fixture YAML.
Apply this diff to test the default:
- it "#private_output_path returns correct path" do
- private_output_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/ssr-generated").to_s
-
- expect(config.private_output_path.to_s).to eq private_output_path
- end
+ it "#private_output_path returns default cache_path when unset" do
+ private_output_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/tmp/shakapacker").to_s
+ expect(config.private_output_path.to_s).to eq private_output_path
+ endOptionally, add a separate example to assert a custom value by stubbing:
- allow(config).to receive(:fetch).with(:private_output_path).and_return("ssr-generated")
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| it "#private_output_path returns correct path" do | |
| private_output_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/ssr-generated").to_s | |
| expect(config.private_output_path.to_s).to eq private_output_path | |
| end | |
| it "#private_output_path returns default cache_path when unset" do | |
| private_output_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/tmp/shakapacker").to_s | |
| expect(config.private_output_path.to_s).to eq private_output_path | |
| end |
🧰 Tools
🪛 GitHub Actions: Ruby based checks
[error] 60-60: RSpec failure in Shakapacker::Configuration: TypeError - no implicit conversion of nil into String
🤖 Prompt for AI Agents
In spec/shakapacker/configuration_spec.rb around lines 57 to 61, the test
expects "ssr-generated" but the configuration default is different
(tmp/shakapacker), so update the test to either assert the documented default by
changing the expected path to File.expand_path(File.join(File.dirname(__FILE__),
"./test_app/tmp/shakapacker")) or modify the test fixture to set
private_output_path to "ssr-generated" in the YAML used by this spec;
alternatively add a separate example that stubs the fetch call (allow(config).to
receive(:fetch).with(:private_output_path).and_return("ssr-generated")) and
asserts the custom value.
Code Review for PR #592: Add private_output_path configuration for SSR bundlesThank you for this contribution! I have reviewed the changes and overall this is a well-implemented feature that provides valuable functionality for SSR bundle management. Here is my detailed feedback: ✅ StrengthsCode Quality
Documentation
Testing
🔍 Observations & Suggestions1. Default Value HandlingThe implementation relies on the defaults from lib/install/config/shakapacker.yml, but there is no explicit default value defined there. The config only has a commented example. This means:
Recommendation: Either:
2. Test ConfigurationThe test at spec/shakapacker/configuration_spec.rb:57-60 expects the path to be ./test_app/ssr-generated, but I do not see private_output_path: ssr-generated added to spec/shakapacker/test_app/config/shakapacker.yml. This test might be passing accidentally or relying on side effects. Recommendation: Add private_output_path: ssr-generated to the test config file for explicit testing. 3. Security Considerations✅ No security concerns identified. The path joining is done safely using root_path.join which prevents path traversal attacks. 4. Performance✅ No performance impact. The method follows the same lazy-loading pattern as other configuration methods. 5. Backward Compatibility✅ Fully backward compatible. This is an additive change that does not affect existing functionality. 📝 Minor Suggestions
🎯 Overall AssessmentThis is a solid implementation that adds valuable functionality for SSR use cases. The main concern is the missing default value handling which should be addressed before merging. Once that is fixed, this PR is ready to go! Great work on maintaining code quality and following the project patterns! 👍 |
ee40ffb to
a1e051c
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
CHANGELOG.md (1)
442-444: Add compare links for v9.0.0.beta.2Please extend the footer references so readers can click through to the new beta diff, and make sure the
[Unreleased]anchor now compares against that tag.-[Unreleased]: https://github.com/shakacode/shakapacker/compare/v8.4.0...main +[Unreleased]: https://github.com/shakacode/shakapacker/compare/v9.0.0.beta.2...main +[v9.0.0.beta.2]: https://github.com/shakacode/shakapacker/compare/v8.4.0...v9.0.0.beta.2README.md (1)
934-942: Clarify the resolved output pathBecause
Configuration#private_output_pathjoins the value withRails.root, saying it “outputs tossr-generated/” can read as if it’s relative. A quick tweak keeps the docs precise.-private_output_path: ssr-generated # outputs to => ssr-generated/ +private_output_path: ssr-generated # resolves to => <Rails.root>/ssr-generated
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
spec/dummy/Gemfile.lockis excluded by!**/*.lock
📒 Files selected for processing (5)
CHANGELOG.md(1 hunks)README.md(1 hunks)lib/install/config/shakapacker.yml(1 hunks)lib/shakapacker/configuration.rb(1 hunks)spec/shakapacker/configuration_spec.rb(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- spec/shakapacker/configuration_spec.rb
- lib/shakapacker/configuration.rb
- lib/install/config/shakapacker.yml
⏰ 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). (20)
- GitHub Check: Testing (ubuntu-latest, 3.3, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Testing (ubuntu-latest, 3.1, gemfiles/Gemfile-rails.7.2.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.1, gemfiles/Gemfile-rails.7.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.1, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.3, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.4, gemfiles/Gemfile-rails.8.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.2, gemfiles/Gemfile-rails.7.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.4, gemfiles/Gemfile-rails.7.2.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.2, gemfiles/Gemfile-rails.8.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.0, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.3, gemfiles/Gemfile-rails.8.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.3, gemfiles/Gemfile-rails.7.2.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.2, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.3, gemfiles/Gemfile-rails.7.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.2, gemfiles/Gemfile-rails.7.2.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.1, gemfiles/Gemfile-rails.7.2.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.0, gemfiles/Gemfile-rails.7.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 2.7, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 2.7, gemfiles/Gemfile-rails.7.0.x)
- GitHub Check: claude-review
a1e051c to
3b2e23a
Compare
This adds a new configuration option `private_output_path` to shakapacker that allows specifying a separate output directory for server-side rendering bundles that shouldn't be served publicly. Key changes: - Add `private_output_path` method to Configuration class that joins the path with root_path - Add configuration to default shakapacker.yml template with documentation - Add test coverage for the new configuration option This feature supports React on Rails' improved bundle path resolution for server-side rendering, providing a cleaner separation between public client bundles and private server bundles. The default path is commented out in the config template, allowing users to opt-in when needed. Related to react-on-rails feature/improve-bundle-path-resolution branch work. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add entry to CHANGELOG.md for unreleased version 8.5.0 - Document private_output_path configuration option in README.md - Explain use case for SSR bundles that shouldn't be served publicly 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Update private_output_path method to return nil when config value is not set - Add default private_output_path: ssr-generated to shakapacker.yml - This prevents errors when the config option is not explicitly set
The comment now correctly states that private_output_path defaults to 'ssr-generated'
75a3216 to
d32df0e
Compare
Code Review for PR #592: Add private_output_path configuration for SSR bundlesThank you for this contribution! I've reviewed the PR and have the following feedback: ✅ Strengths
🔍 Issues Found1. Test Failure - Missing Configuration in Test File 🐛The test at Fix needed: Add 2. Inconsistent Default Behavior
|
This PR comprehensively addresses all review feedback from the original private_output_path feature (PR #592), ensuring robust validation and consistency with the codebase patterns. Key Improvements: - Added missing private_output_path configuration to test files, fixing test failures - Made private_output_path optional by commenting out the default value in config template - Implemented path validation to prevent private and public output paths from being identical - Enhanced validation to handle symbolic links and relative paths with .. correctly - Improved code readability by extracting path resolution logic into a dedicated method - Added comprehensive test coverage for edge cases including relative paths and validation behavior - Consolidated redundant documentation into clearer, more concise comments - Added migration guide for React on Rails users in README Technical Changes: - Modified lib/shakapacker/configuration.rb to add validate_output_paths! and resolve_paths_for_comparison methods - Updated spec/shakapacker/test_app/config/shakapacker.yml with private_output_path: ssr-generated - Changed lib/install/config/shakapacker.yml to comment out default private_output_path value - Enhanced path resolution using realpath/cleanpath for proper symbolic link handling - Removed memoization to maintain consistency with other path methods in the class - Added validation tests in spec/shakapacker/configuration_spec.rb for various edge cases Impact on Existing Installations: - No breaking changes - private_output_path remains optional - Existing installations without private_output_path configured will continue working unchanged - Validation only runs when private_output_path is explicitly configured - The validation flag ensures checks run only once per configuration instance Impact on New Installations: - Config template now clearly shows private_output_path as an optional feature - Better documentation helps users understand when and how to use this feature - Validation prevents misconfiguration errors at startup, catching path conflicts early - Proper handling of symbolic links and relative paths ensures reliable path resolution This ensures the private_output_path feature is production-ready for server-side rendering use cases, particularly benefiting React on Rails users who need separate bundle outputs for client and server code. The implementation follows existing codebase patterns while adding robust validation to prevent configuration errors.
The private_output_path feature (PR #592) added the Ruby-side method but not the JS-side computed property. This caused consumers like React on Rails to always get undefined for config.privateOutputPath, breaking config sync and producing false warnings on every build. Follows the same pattern as config.outputPath: resolves the raw YAML string to an absolute path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The private_output_path feature (PR #592) added the Ruby-side method but not the JS-side computed property. This caused consumers like React on Rails to always get undefined for config.privateOutputPath, breaking config sync and producing false warnings on every build. Follows the same pattern as config.outputPath: resolves the raw YAML string to an absolute path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The private_output_path feature (PR #592) added the Ruby-side method but not the JS-side computed property. This caused consumers like React on Rails to always get undefined for config.privateOutputPath, breaking config sync and producing false warnings on every build. Follows the same pattern as config.outputPath: resolves the raw YAML string to an absolute path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The private_output_path feature (PR #592) added the Ruby-side method but not the JS-side computed property. This caused consumers like React on Rails to always get undefined for config.privateOutputPath, breaking config sync and producing false warnings on every build. Follows the same pattern as config.outputPath: resolves the raw YAML string to an absolute path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
private_output_pathconfiguration option to shakapacker for server-side rendering bundlesMotivation
This feature addresses the need for better separation between public client bundles and private server-side rendering bundles. Currently, React on Rails is working on improving bundle path resolution (see
feature/improve-bundle-path-resolutionbranch), and this shakapacker feature provides the foundational configuration support.Changes
private_output_pathmethod toShakapacker::Configurationthat joins the configured path with the root pathlib/install/config/shakapacker.ymlwith clear explanation of its purposeUsage
Users can now configure a separate output directory for SSR bundles in their
shakapacker.yml:Testing
private_output_pathconfigurationRelated Work
This supports the ongoing work in React on Rails for improving bundle path resolution and SSR bundle handling.
Target Release
8.5.0
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation
Tests