-
-
Notifications
You must be signed in to change notification settings - Fork 638
Add suppress_unused_component_warnings config option #2136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Add ability to suppress console.warn messages about registered components that are not used on a page. This is useful in production environments where many React components are registered globally but only a subset are used on each page. Configuration: config.suppress_unused_component_warnings = true Changes: - Add suppress_unused_component_warnings config option (default: false) - Pass option to railsContext as suppressUnusedComponentWarnings - Update CallbackRegistry to check the option before logging warnings - Update TypeScript types and RBS signatures - Update documentation and tests Closes #2117 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
Warning Rate limit exceeded@justin808 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 22 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 (10)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 #2136: Add suppress_unused_component_warnings config option✅ Overall AssessmentThis is a well-implemented feature that addresses a legitimate production use case. The implementation is clean, follows project conventions, and includes proper documentation and type safety. 🎯 Strengths
🔍 Observations & Minor Suggestions1. Test Coverage Gap (Low Priority)While existing tests were updated to include the new property, there are no dedicated tests for the new functionality itself. Consider adding: Ruby side test: # In react_on_rails/spec/react_on_rails/configuration_spec.rb
it 'defaults suppress_unused_component_warnings to false' do
expect(ReactOnRails.configuration.suppress_unused_component_warnings).to be false
end
it 'allows setting suppress_unused_component_warnings' do
ReactOnRails.configure do |config|
config.suppress_unused_component_warnings = true
end
expect(ReactOnRails.configuration.suppress_unused_component_warnings).to be true
end
it 'includes suppressUnusedComponentWarnings in rails_context' do
# Test that the helper passes this through to rails_context
endTypeScript side test: // In packages/react-on-rails-pro/tests/CallbackRegistry.test.ts (create if needed)
describe('CallbackRegistry unused component warnings', () => {
it('logs warnings when suppressUnusedComponentWarnings is false', () => {
// Mock getRailsContext to return suppressUnusedComponentWarnings: false
// Register a component but don't use it
// Trigger timeout
// Expect console.warn to have been called
});
it('suppresses warnings when suppressUnusedComponentWarnings is true', () => {
// Mock getRailsContext to return suppressUnusedComponentWarnings: true
// Register a component but don't use it
// Trigger timeout
// Expect console.warn NOT to have been called
});
});Note: This is not blocking, but would improve confidence in the feature and prevent regressions. 2. Potential Null Safety EnhancementIn Consider making this explicit: const suppressWarnings = getRailsContext()?.suppressUnusedComponentWarnings ?? false;This makes it clear that the default is 3. Configuration ValidationThe Ruby def check_suppress_unused_component_warnings
# Coerce nil to false (already done in initialize)
self.suppress_unused_component_warnings = false if suppress_unused_component_warnings.nil?
# Validate it's actually a boolean (not just truthy/falsy)
unless [true, false].include?(suppress_unused_component_warnings)
raise ReactOnRails::Error, "suppress_unused_component_warnings must be true or false"
end
endThis would catch cases where someone sets it to a string or other value. 🔒 Security & Performance
📋 Checklist (Based on CLAUDE.md)
🎬 RecommendationAPPROVE with minor suggestions This PR is ready to merge. The suggestions above are non-blocking improvements that could be addressed in a follow-up PR if desired. The core implementation is solid, well-documented, and follows all project conventions. Great work on addressing issue #2117! This will be helpful for production environments with many registered components. References:
|
Code Review - PR #2136: Add suppress_unused_component_warnings config option✅ Overall AssessmentThis is a well-implemented feature that addresses a legitimate production concern (issue #2117). The implementation is clean, follows project conventions, and the test plan confirms all critical checks passed. 🎯 Strengths
🔍 Issues & Concerns❌ CRITICAL: Wrong PR Number in CHANGELOGThe CHANGELOG entry references: [PR 2125](https://github.com/shakacode/react_on_rails/pull/2125)But this is PR #2136. This needs to be corrected before merge.
|
- Fix CHANGELOG PR reference (was 2125, now correct 2136) - Add unit tests for suppress_unused_component_warnings configuration - Test default value is false - Test can be set to true - Test can be set to false explicitly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Addressed Review FeedbackI've addressed the review comments in commit 6088576: ✅ Fixed Issues
ℹ️ Notes on Other SuggestionsRe: default already in configuration hash: The default is already present at lines 67-70 in # Set to true to suppress warnings about registered components not being used on a page.
# This can be useful in production environments where many components are registered globally
# but only a subset are used on each page.
suppress_unused_component_warnings: false,Re: explicit null coalescing in TypeScript: The current code Monitoring CI for the updated commit. |
Code Review for PR 2136SummaryThis PR adds a suppress_unused_component_warnings configuration option to allow users to disable console warnings about registered components that aren't used on a page. Overall, the implementation is solid and well-tested, but there's ONE CRITICAL BUG that needs to be fixed. CRITICAL ISSUE - Missing Configuration DefaultLocation: react_on_rails/lib/react_on_rails/configuration.rb:69 Problem: The new suppress_unused_component_warnings option is NOT included in the default configuration hash passed to Configuration.new. Looking at the code, component_registry_timeout is there, but suppress_unused_component_warnings is missing from the hash on line 34-70. Impact: When users call ReactOnRails.configuration without explicitly configuring this option, it will be nil instead of false. While line 177 has a fallback (|| false), this creates inconsistency and could cause unexpected behavior if the configuration object is inspected or serialized before initialization completes. Fix Required: Add suppress_unused_component_warnings: false to the default configuration hash in ReactOnRails.configuration (around line 67, after component_registry_timeout) Positive Aspects
Minor ObservationsAttr Accessor Placement (Non-blocking): The suppress_unused_component_warnings attr_accessor is separated from component_registry_timeout by other unrelated attributes. Consider placing it immediately after component_registry_timeout for better logical grouping since they're related to the component registry feature. Test Coverage (Non-blocking): The PR updates test fixtures but doesn't add explicit tests for the new configuration option. Consider adding tests verifying: (1) default value is false, (2) option can be set to true, (3) it's properly passed to railsContext. However, given the simplicity of the feature and comprehensive manual testing noted in the PR description, this is optional. Optional Chaining Safety: The code uses getRailsContext()?.suppressUnusedComponentWarnings which is good defensive programming. This will safely default to undefined (falsy) if the context isn't available. CI Failure AnalysisI see there's one CI failure in rspec-dummy-app-node-renderer. This appears to be unrelated to your changes since: (1) Your changes are purely configuration-related, (2) No changes to node renderer code, (3) Other integration tests pass successfully. However, per the repo's CLAUDE.md guidelines, you should verify this isn't a pre-existing failure by checking if master is passing for this workflow. RecommendationsMust Fix:
Should Consider:
Nice to Have:
The implementation is well-designed and thoroughly documented, but needs ONE CRITICAL FIX before merging. Once the default configuration value is added, this will be ready to ship. Great work on maintaining consistency across Ruby, TypeScript, and RBS type definitions! |
Code Review - PR #2136This is a well-implemented feature that adds the ability to suppress unused component warnings. Here's my detailed feedback: ✅ Strengths
🔍 Minor Observations
📋 Checklist ReviewBased on CLAUDE.md requirements:
🎯 RecommendationAPPROVE - This PR is production-ready and follows all repository conventions. The implementation is clean, well-tested, and properly documented. The only suggestion is adding a test for the CallbackRegistry behavior, but this is optional since the integration is straightforward and the configuration is well-tested. Great work addressing issue #2117! 🚀 |
Code Review - PR #2136: Add suppress_unused_component_warnings config optionSummaryThis PR adds a new configuration option to suppress console warnings about unused registered components. The implementation is clean and follows React on Rails conventions well. Strengths
Issues and Suggestions1. Missing Configuration Attribute (CRITICAL)The new suppress_unused_component_warnings attribute is NOT added to the attr_accessor list in configuration.rb:74-86. This means the getter/setter methods are not defined and the configuration won't work at runtime. Fix needed in react_on_rails/lib/react_on_rails/configuration.rb line 85 2. Inconsistent Default HandlingThe pattern in configuration.rb:177 uses || false which will incorrectly treat explicit false as nil. Consider using the ternary pattern used elsewhere or relying on the default value. 3. Pro-Only Feature ClarityThe changelog notes this is Pro-only but the configuration is in the open-source gem. Consider adding a comment in configuration.rb noting this only affects Pro users. 4. Potential Race Condition (Minor)In CallbackRegistry.ts:58, the getRailsContext() call happens during the timeout callback. Consider caching the config value at initialization for more predictable behavior. SecurityNo security concerns identified. PerformanceNegligible impact. The check happens during timeout callback only. Test CoverageGood coverage of the configuration behavior. Consider adding an integration test that verifies warnings are actually suppressed. Action ItemsMust Fix Before Merge:
Should Fix:
Nice to Have:
VerdictGood implementation overall with proper documentation and testing. CRITICAL ISSUE: Missing attr_accessor will cause runtime failures. Please fix before merging. Review by Claude Code |
Code Review for PR #2136Overall AssessmentThis is a well-implemented feature that addresses a legitimate use case (issue #2117). The code quality is high, and the implementation follows React on Rails conventions. However, there is one critical issue that needs to be addressed before merging. Critical IssueMissing Default Value in Configuration HashLocation: react_on_rails/lib/react_on_rails/configuration.rb:33-70 The suppress_unused_component_warnings option is not included in the default configuration hash passed to Configuration.new. Looking at the current code, the hash includes component_registry_timeout but is missing the new option. Impact: Without this, the configuration option will be nil until the initialize method applies the || false fallback. While this works, it is fragile and inconsistent with other configuration options. Fix Required: Add suppress_unused_component_warnings: false to the default configuration hash, between component_registry_timeout and generated_component_packs_loading_strategy. Code Quality ObservationsExcellent DocumentationThe documentation in docs/api-reference/configuration.md is clear and helpful:
Comprehensive Test CoverageThe RSpec tests in configuration_spec.rb properly test:
TypeScript test fixtures updated to include the new property in ClientRenderer.test.ts Type Safety Maintained
Implementation ReviewCallbackRegistry Implementation (packages/react-on-rails-pro/src/CallbackRegistry.ts)The implementation correctly wraps the warning forEach loop in a conditional check. The optional chaining on getRailsContext() provides safe fallback behavior - if the context is missing, suppressWarnings will be undefined, which is falsy, so warnings will be shown by default. This is correct! Configuration Initialization PatternThe line self.suppress_unused_component_warnings = suppress_unused_component_warnings || false provides correct default behavior but is fragile because it relies on the parameter being nil rather than having an explicit default in the configuration hash. This is why adding it to the default hash is important. Runtime BehaviorThe code safely handles missing configuration via optional chaining. If getRailsContext() returns null/undefined, warnings will be shown (correct default behavior). Testing Checklist ReviewAccording to the PR description:
Question: Was the actual behavior manually tested in a browser?
It would be helpful to confirm manual browser testing occurred. Strengths
Security & PerformanceSecurity: No concerns identified - boolean config value, no user input, client-side only Performance: Minimal impact - single boolean check before logging, only runs during timeout callback Final VerdictStatus: Needs Changes (one critical fix required) Required Before Merge:
Optional:
Once the default configuration value is added, this PR will be ready to merge. The implementation is solid and follows all project conventions. Great work overall! References:
|
Add suppressUnusedComponentWarnings to the rails_context fixture in the Pro helper spec to match the updated rails_context structure. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
CI Fix PushedPushed commit 76a6429 to fix the failing Pro integration test. Issue: The test fixture in Fix: Added Note on other CI failure: The "JS unit tests for Renderer package" workflow is a pre-existing failure on master (failing since Nov 23rd), not related to this PR. |
Code Review: Add suppress_unused_component_warnings config option✅ Overall AssessmentThis is a well-implemented, clean addition that solves a real problem in production environments. The code quality is high, testing is comprehensive, and documentation is clear. 🎯 Strengths1. Clean Implementation
2. Excellent Type Safety
3. Smart Design ChoiceThe check
4. Comprehensive Testing
5. Good Documentation
💡 Minor Suggestions (Optional Improvements)1. Consider Adding Integration TestWhile unit tests are solid, consider adding an integration test that verifies:
Example location: 2. CHANGELOG Placement ConsiderationThe feature is correctly placed in the main CHANGELOG.md since it affects the open-source package's configuration. However, you might also consider mentioning it in CHANGELOG_PRO.md since:
Per CLAUDE.md guidelines:
This is a judgment call—current placement is valid, but dual-changelog entry would be more discoverable for Pro users. 🔍 Technical Details VerifiedRuby Configuration (
|
Code Review: Add suppress_unused_component_warnings config optionOverall, this is a well-implemented feature with good test coverage and documentation. The implementation is clean, follows project conventions, and addresses a real need for production environments. Below are my observations: ✅ Strengths
🔍 Observations & Potential Issues1. Missing from
|
Code Review Feedback✅ Overall AssessmentThis PR successfully implements the 📋 Code Quality & Best PracticesStrengths:
Minor Observation:
🐛 Potential IssuesNo critical issues found. However, one observation: Configuration Initialization (line 174 in configuration.rb): self.suppress_unused_component_warnings = suppress_unused_component_warnings || falseThis line uses
This is correct, but could be simplified for clarity: self.suppress_unused_component_warnings = suppress_unused_component_warnings.nil? ? false : suppress_unused_component_warningsOr even simpler since self.suppress_unused_component_warnings = \!\!suppress_unused_component_warningsHowever, the current implementation is consistent with how other boolean config options are handled in the same file (e.g., see line 158 for 🚀 Performance ConsiderationsNo performance concerns. The implementation:
🔒 Security ConcernsNo security issues. This is a client-side display configuration that:
🧪 Test CoverageExcellent test coverage: ✅ Ruby configuration tests (
✅ Integration tests (
✅ TypeScript tests (
Missing (but optional) test coverage:
Recommendation: Consider adding a test that verifies when 📚 DocumentationExcellent documentation:
✨ Additional Suggestions
🎯 ConclusionThis PR is ready to merge after:
The implementation is solid, follows project conventions, and solves the stated problem (issue #2117) effectively. Great work! 🚀 📝 Nitpicks (Optional)None! The code is clean and follows the project's style guide. 🤖 Review conducted by Claude Code |
Response to Code ReviewThank you for the thorough review! Here's my response to the observations: ✅ Observation #1: Default in
|
Summary
suppress_unused_component_warningsconfiguration option to disable console warnings about registered components that are not used on a pageconfig.suppress_unused_component_warnings = truein your React on Rails initializer to suppress these warningsChanges
suppress_unused_component_warningsconfig option to Ruby configuration (default: false)suppressUnusedComponentWarningsRailsContext) and RBS signaturesdocs/api-reference/configuration.mdTest plan
bundle exec rubocop- passedbundle exec rake run_rspec:gem- 290 examples, 0 failuresbundle exec rake rbs:validate- passedpnpm run type-check- passed for both react-on-rails and react-on-rails-pro packagesCloses #2117
🤖 Generated with Claude Code