-
-
Notifications
You must be signed in to change notification settings - Fork 638
Migrate from Babel to SWC for faster JavaScript transpilation #1932
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
Conversation
This commit switches the JavaScript transpiler from Babel to SWC (Speedy Web Compiler), providing approximately 20x faster compilation times. Key changes: - Install @swc/core and swc-loader dependencies - Create SWC configuration files for both dummy apps - Update shakapacker.yml to use SWC instead of Babel - Document SWC migration process and RSC compatibility findings Performance improvements: - Build times reduced from minutes to seconds - Significantly faster Hot Module Replacement (HMR) - Lower memory usage during builds React Server Components compatibility: - SWC support for RSC is EXPERIMENTAL and UNSTABLE as of 2025 - All 305 RSpec tests pass successfully with SWC - For standard React apps: SWC is fully compatible and recommended - For RSC: Use with caution, extensive testing required The comprehensive migration guide in docs/swc-migration.md covers: - Step-by-step migration instructions - Feature comparison between Babel and SWC - RSC compatibility status and recommendations - Troubleshooting common issues - Testing results Testing: - All 305 RSpec examples pass with 0 failures - Build compilation successful with SWC - Linting passes with no offenses 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Warning Rate limit exceeded@justin808 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 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)
WalkthroughAdds SWC transpiler support to React on Rails with Shakapacker 9.0+. Introduces a comprehensive migration guide document, updates package.json with SWC dependencies, creates a new SWC configuration file, modifies shakapacker.yml to use SWC instead of Babel, and updates knip.ts to include SWC entries. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related issues
Possibly related PRs
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 |
PR Review: Migrate from Babel to SWC for faster JavaScript transpilationSummaryThis PR successfully migrates the project from Babel to SWC as the JavaScript transpiler, which is a significant performance improvement. The implementation looks solid overall with comprehensive documentation and testing. ✅ Strengths1. Excellent Documentation
2. Thorough Testing
3. Configuration Quality
4. Good Practice
🔍 Areas for Consideration1. Babel Configuration Not RemovedThe existing Question: Should these be:
Impact: Developers might be confused about which transpiler is actually being used. The 2. CHANGELOG Entry MissingAccording to the project's
This is a significant performance improvement (20x faster compilation) and should have a CHANGELOG entry under Suggested entry: - **SWC Transpiler Migration**: Migrated from Babel to SWC for JavaScript/TypeScript transpilation, providing ~20x faster compilation times. Added comprehensive migration guide (`docs/swc-migration.md`) with step-by-step instructions. Note: SWC support for React Server Components is experimental; projects requiring stable RSC should continue using Babel. [PR 1932](https://github.com/shakacode/react_on_rails/pull/1932) by [justin808](https://github.com/justin808).3. SWC Config Differences Between AppsThere's a subtle difference between the two SWC configs: Open Source ( parser: {
syntax: 'ecmascript',
jsx: true,
dynamicImport: true,
}Pro ( parser: {
syntax: 'ecmascript',
jsx: true,
dynamicImport: true,
exportDefaultFrom: true, // ← Extra option
}Question: Is 4. Documentation: Version ConstraintsThe migration guide mentions:
Consider adding:
5. Generator TemplatesThe file Question: Should the generator be updated to:
This ensures new projects created with React on Rails get SWC by default. 6. Shakapacker Version Bump in Gemfile.lockThe PR shows Shakapacker upgrading from - shakapacker (9.0.0)
+ shakapacker (9.1.0)Consider: Should this be split into a separate PR or at least mentioned in the PR description? It's technically a different change from the Babel→SWC migration. 🔒 Security Considerations✅ No security concerns identified:
⚡ Performance Considerations✅ Excellent performance improvements:
Note: This is a major win for developer experience. 🧪 Test Coverage✅ Test coverage is adequate:
Suggestion: Consider adding a simple integration test that verifies SWC is actually being used (checking for SWC-specific output or behavior). 📝 Code QualityMinor: Code StyleAll code follows project conventions. No RuboCop or ESLint issues expected. Documentation QualityThe migration guide is well-written, but consider:
🎯 RecommendationsCritical (Should Address Before Merge):
High Priority:
Medium Priority:
🎉 Overall AssessmentThis is excellent work! The migration is well-executed with:
With the minor improvements suggested above (especially the CHANGELOG entry), this PR will be ready to provide significant performance improvements to React on Rails users. Recommendation: ✅ Approve with minor changes requested Great job on the migration and especially the thorough RSC compatibility research! 🚀 |
Code Review for PR #1932: Migrate from Babel to SWCSummaryThis PR successfully migrates from Babel to SWC for JavaScript transpilation. The implementation is well-structured with comprehensive documentation. Below are my findings: ✅ Strengths1. Excellent Documentation
2. Minimal, Targeted Changes
3. Testing
🔍 Code Quality Issues1. Missing Newlines at End of Files
|
Code Review: Babel to SWC MigrationThank you for this comprehensive migration PR! Overall, this is a well-executed change with excellent documentation. Here's my detailed review: ✅ Strengths1. Excellent Documentation
2. Configuration Quality
3. Testing Coverage
|
| Category | Rating | Notes |
|---|---|---|
| Code Quality | ⭐⭐⭐⭐½ | Clean configs, good structure |
| Documentation | ⭐⭐⭐⭐⭐ | Excellent migration guide |
| Testing | ⭐⭐⭐⭐☆ | Good coverage, could add SWC-specific tests |
| Performance | ⭐⭐⭐⭐⭐ | Significant improvements |
| Security | ⭐⭐⭐⭐⭐ | No concerns |
Overall: 4.5/5 - Excellent work with a few items to address
✅ Pre-Merge Checklist
Before merging, please verify:
- Resolve the Babel plugin migration issue for Pro app (macros, @loadable/babel-plugin)
- Make SWC configs consistent (exportDefaultFrom)
- Document why Babel dependencies remain or remove them
- Clarify Shakapacker version (9.0.0 vs 9.1.0)
- Add CHANGELOG entry
- Run
bundle exec rubocopand ensure it passes (per CLAUDE.md requirements) - Verify all files end with newlines (per CLAUDE.md requirements)
- Consider adding actual benchmark numbers to the migration guide
💡 Summary
This is a high-quality PR that brings significant performance improvements to React on Rails. The main blocker is understanding how the Pro app handles the missing Babel plugin functionality. Once that's clarified/resolved, this should be good to merge!
The documentation is particularly impressive and will be very helpful for users migrating their projects.
Great work! 🚀
Code Review: SWC Migration PRI've reviewed this PR and overall it looks excellent! The migration from Babel to SWC is well-executed with comprehensive documentation and testing. Here's my detailed feedback: ✅ Strengths1. Excellent Documentation
2. Configuration QualityThe SWC configs (
3. Test Coverage
🔍 Issues & SuggestionsCritical: Missing Trailing Newlines
|
Add @swc/core and swc-loader to ignoreDependencies and include swc.config.js as entry point to prevent knip from marking them as unused. Fixes lint CI failure.
Code Review - SWC MigrationThank you for this well-structured PR migrating from Babel to SWC! Overall, this is a high-quality change that brings significant performance improvements. Here's my detailed review: ✅ Strengths
🔍 Issues & Concerns1. Configuration Inconsistency (Minor)The two SWC config files differ slightly:
Recommendation: Ensure both configs are aligned unless there's a specific reason for the difference. The Pro version appears more complete. 2. Documentation Syntax Error (Critical)In jsc: {
parser: {
decorators: true; // ← SEMICOLON should be COMMA
}
}This will cause a syntax error if users copy-paste this code. Should be: jsc: {
parser: {
decorators: true
}
}3. Shakapacker Version Update (Question)The PR shows
Question: Is the Shakapacker 9.1.0 upgrade intentional? Should it be documented separately? 4. RSC Warning Placement (Suggestion)The extensive RSC warnings are valuable but might overwhelm users who don't use RSC. Consider:
5. Missing Test Evidence for Pro VersionThe PR mentions "All 305 RSpec tests pass" but doesn't explicitly confirm Pro package tests passed with SWC. Recommendation: Add a note confirming Pro specs also pass (e.g., 🛡️ Security Considerations✅ No security concerns identified:
⚡ Performance Considerations✅ Excellent performance improvements as stated:
🧪 Test Coverage✅ Good test coverage reported:
Recommendation: Add a test that verifies SWC is actually being used (e.g., check webpack config in specs). 📝 Code Quality✅ Generally excellent:
🎯 Breaking Changes✅ No breaking changes for end users:
📋 Action ItemsMust Fix Before Merge:
Should Consider: Nice to Have: 📚 Documentation QualityExcellent - The migration guide is one of the best I've seen:
Only improvement: Fix the syntax error and consider a "Quick Start" section at the top. ✨ Overall AssessmentRating: 8.5/10 This is a solid, well-researched PR that brings significant value. The main issues are minor:
Once the syntax error is fixed and configs are aligned, this will be ready to merge! Recommendation: REQUEST CHANGES (due to syntax error in documentation) After fixes: APPROVE Great work on this migration! 🚀 |
- Revert react_on_rails_pro/spec/dummy back to Babel transpiler - Remove SWC config from Pro dummy app - Update documentation to clarify only spec/dummy uses SWC - Pro app stays with Babel for RSC stability This provides a safer migration path where standard React on Rails apps can benefit from SWC's 20x performance improvement, while Pro apps with React Server Components maintain stability with Babel until SWC RSC support matures.
Pull Request Review: Babel to SWC MigrationOverall AssessmentVerdict: ✅ Excellent PR with thoughtful approach and comprehensive documentation This PR demonstrates a mature, risk-aware migration strategy by adopting SWC for the standard dummy app while keeping Babel for the Pro/RSC features. The implementation is clean, well-documented, and follows best practices. Strengths1. Smart Gradual Migration StrategyThe dual-configuration approach (SWC for 2. Exceptional Documentation (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
spec/dummy/Gemfile.lockis excluded by!**/*.lockyarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (5)
docs/swc-migration.md(1 hunks)knip.ts(2 hunks)package.json(2 hunks)spec/dummy/config/shakapacker.yml(1 hunks)spec/dummy/config/swc.config.js(1 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: alexeyr-ci2
Repo: shakacode/react_on_rails PR: 1732
File: spec/dummy/client/app-react16/startup/ReduxSharedStoreApp.client.jsx:40-44
Timestamp: 2025-04-26T21:55:55.874Z
Learning: In the react_on_rails project, files under `app-react16` directories are copied/moved to corresponding `/app` directories during the conversion process (removing the `-react16` suffix), which affects their relative import paths at runtime.
Learnt from: justin808
Repo: shakacode/react_on_rails PR: 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-01-23T18:20:45.824Z
Learnt from: alexeyr-ci
Repo: shakacode/react_on_rails PR: 1687
File: spec/dummy/package.json:0-0
Timestamp: 2025-01-23T18:20:45.824Z
Learning: When adding or updating dependencies in spec/dummy/package.json, maintain version consistency with other package.json files in the codebase to avoid potential version conflicts.
Applied to files:
package.json
📚 Learning: 2025-09-16T08:01:11.146Z
Learnt from: justin808
Repo: shakacode/react_on_rails PR: 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:
package.jsonknip.tsdocs/swc-migration.md
📚 Learning: 2025-04-26T21:55:55.874Z
Learnt from: alexeyr-ci2
Repo: shakacode/react_on_rails PR: 1732
File: spec/dummy/client/app-react16/startup/ReduxSharedStoreApp.client.jsx:40-44
Timestamp: 2025-04-26T21:55:55.874Z
Learning: In the react_on_rails project, files under `app-react16` directories are copied/moved to corresponding `/app` directories during the conversion process (removing the `-react16` suffix), which affects their relative import paths at runtime.
Applied to files:
docs/swc-migration.md
📚 Learning: 2025-02-18T13:08:01.477Z
Learnt from: AbanoubGhadban
Repo: shakacode/react_on_rails PR: 1644
File: lib/react_on_rails/helper.rb:190-197
Timestamp: 2025-02-18T13:08:01.477Z
Learning: RSC support validation in React on Rails Pro is handled through a chain of validations:
1. Pro version check in `run_stream_inside_fiber`
2. RSC support check during pack generation via `ReactOnRailsPro.configuration.enable_rsc_support`
3. RSC support validation during component registration
This makes additional validation in the helper methods unnecessary.
Applied to files:
docs/swc-migration.md
🪛 markdownlint-cli2 (0.18.1)
docs/swc-migration.md
189-189: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
⏰ 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: build
- GitHub Check: build (20)
- GitHub Check: build (22)
- GitHub Check: rspec-package-tests (3.2, minimum)
- GitHub Check: rspec-package-tests (3.4, latest)
- GitHub Check: build-dummy-app-webpack-test-bundles (3.4, 22, latest)
- GitHub Check: markdown-link-check
- GitHub Check: claude-review
🔇 Additional comments (6)
knip.ts (2)
41-43: LGTM!The SWC dependencies are correctly added to
ignoreDependencieswith a clear comment explaining their usage in dummy apps. This aligns with the dependencies added inpackage.json.
103-104: LGTM!The SWC configuration file is correctly included in the spec/dummy workspace entry points. This ensures Knip recognizes the new config file as intentionally used.
spec/dummy/config/shakapacker.yml (1)
8-9: LGTM!The transpiler configuration is correctly updated to use SWC with a clear comment explaining the performance benefit. This change aligns with the migration objectives.
spec/dummy/config/swc.config.js (1)
1-28: LGTM!The SWC configuration is well-structured and appropriate:
- Parser settings correctly enable JSX and dynamic imports
- React transform uses the automatic runtime (new JSX transform)
- HMR refresh is properly gated on development mode and dev server
keepClassNames: truepreserves class names for debugging and Stimulus compatibility- Browser targets are sensible (> 0.25%, not dead)
docs/swc-migration.md (1)
1-217: Excellent migration guide!This is a comprehensive and well-structured migration guide that covers:
- Clear step-by-step migration instructions
- Important RSC compatibility warnings and recommendations
- Feature comparison tables for easy reference
- Troubleshooting section for common issues
- Testing validation results
The documentation aligns perfectly with the implementation and provides valuable guidance for users considering the migration.
package.json (1)
22-22: SWC packages are current and secure—no changes needed.The pinned version of @swc/core (^1.15.0) is already the latest available on npm, and no known security vulnerabilities exist for either @swc/core or swc-loader. The dependencies are in good standing.
| ```javascript | ||
| jsc: { | ||
| parser: { | ||
| decorators: true; | ||
| } | ||
| } | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix syntax error in decorators example.
Line 176 uses a semicolon instead of a comma in the JavaScript object.
Apply this diff:
jsc: {
parser: {
- decorators: true;
+ decorators: true,
}
}📝 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.
| ```javascript | |
| jsc: { | |
| parser: { | |
| decorators: true; | |
| } | |
| } | |
| ``` | |
| jsc: { | |
| parser: { | |
| decorators: true, | |
| } | |
| } |
🤖 Prompt for AI Agents
In docs/swc-migration.md around lines 173 to 179 the JavaScript object example
for jsc.parser uses a semicolon after "decorators: true" which is invalid
syntax; change the semicolon to a comma (or remove it if last property) so the
object becomes valid JSON/JS object syntax, e.g., ensure properties are
comma-separated and the block reads with "decorators: true," followed by the
closing brace.
Code Review: SWC Migration PROverall AssessmentThis is an excellent, well-executed PR that demonstrates responsible technology adoption. The approach is methodical, well-documented, and appropriately cautious about React Server Components. ✅ Strengths1. Code Quality & Best Practices
2. Documentation Excellence
3. Safe Migration Strategy
4. Dependencies Management
🔍 Observations & Considerations1. Configuration DetailsSWC Config ( // ✅ Good: Uses env from shakapacker
const { env } = require('shakapacker');
// ✅ Good: Automatic React runtime (no need for 'import React')
runtime: 'automatic',
// ✅ Good: Development mode enhancements
development: env.isDevelopment,
refresh: env.isDevelopment && env.runningWebpackDevServer,
// ✅ Good: Keep class names for debugging
keepClassNames: true,Potential Enhancement: Consider documenting whether TypeScript support requires changing 2. Shakapacker ConfigurationThe change from # Using SWC for faster JavaScript transpilation (20x faster than Babel)
javascript_transpiler: swcGood: The comment clearly states the benefit and is more informative than the previous comment. 3. Package DependenciesAdded dependencies:
Note: These are devDependencies, which is appropriate since they're build-time tools. 4. Test CoverageAccording to the PR description:
Excellent: Comprehensive testing across all React on Rails features. 🐛 Potential Issues (Minor)1. Missing swc.config.js in Working DirectoryI noticed that the
Action: Verify the file is included in the commit. 2. Documentation LocationThe new documentation is at the root level (
3. Knip Configuration Entry PointsThe knip.ts update adds SWC dependencies to the ignore list: '@swc/core',
'swc-loader',And adds the config file: 'config/swc.config.js',Good: This prevents false positives for unused dependencies. Consider: Whether 🚀 Performance ConsiderationsExpected Benefits (as documented)
Real-World ImpactThese improvements are substantial for:
🔒 Security ConcernsNo Security Issues Identified ✅
📊 Test Coverage AssessmentExisting Test CoverageThe PR mentions all 305 tests pass, covering:
Recommendations
📝 Documentation Suggestionsdocs/swc-migration.md Improvements
Example Addition:## Quick Start
**For standard React apps (no RSC):**
1. `yarn add -D @swc/core swc-loader`
2. Change `javascript_transpiler: babel` to `javascript_transpiler: swc` in `config/shakapacker.yml`
3. Create `config/swc.config.js` (see below)
4. Test: `bundle exec rake shakapacker:compile`
**For RSC apps:** Stay with Babel for now (see RSC Compatibility section)🎯 RecommendationsMust Have (Before Merge)
Should Have (Before Merge)
Nice to Have (Future PRs)
🏆 Final VerdictAPPROVED ✅ This is a high-quality PR that:
Confidence Level: High ✅The approach is conservative, well-tested, and properly scoped. The decision to keep Pro/RSC on Babel demonstrates good engineering judgment. Minor Action Items:
Great work! This will significantly improve the developer experience for React on Rails users. 🤖 Generated with Claude Code Review based on:
|
Code Review: SWC MigrationThank you for this well-documented PR! The migration from Babel to SWC is a valuable performance improvement. Here's my detailed review: ✅ Strengths1. Excellent Documentation
2. Thoughtful Gradual Migration Strategy
3. Good Configuration
4. Test Coverage
🔍 Issues & RecommendationsCritical: Inconsistent Shakapacker VersionIssue: The - shakapacker (9.0.0)
+ shakapacker (9.1.0)Recommendation:
Code Quality Issues1. Missing Error Handling in SWC ConfigLocation: The config file doesn't handle potential errors from Current: const { env } = require('shakapacker');Recommendation: let env;
try {
({ env } = require('shakapacker'));
} catch (error) {
console.error('Failed to load shakapacker:', error.message);
process.exit(1);
}2. Browser Targets Could Be More SpecificLocation: The browserslist query Current: env: {
targets: '> 0.25%, not dead',
}Recommendation: Consider aligning with modern best practices: env: {
targets: [
'defaults',
'not IE 11',
'maintained node versions'
],
}Or reference a browserslist config file for consistency across tools. Documentation Issues1. Incomplete Troubleshooting SectionLocation: The troubleshooting section mentions solutions but doesn't cover common SWC-specific issues: Recommendations to add: ### Issue: Build Fails with "Cannot find module '@swc/core'"
**Solution**: Clear node_modules and reinstall:
```bash
rm -rf node_modules
yarn installIssue: Fast Refresh Not WorkingSolution: Ensure webpack-dev-server is running and check that:
Issue: Syntax Errors Not Being CaughtSolution: SWC parser is more permissive than Babel. Add TypeScript or ESLint for stricter checking: yarn add -D @typescript-eslint/parser @typescript-eslint/eslint-pluginSecurity Considerations1. Dependency Security ✅The new dependencies look good:
Recommendation: Consider adding Dependabot or Renovate config to keep SWC updated, as it's a rapidly evolving project. 2. No Security ConcernsNo vulnerabilities introduced. The transpiler change doesn't affect runtime security. Performance Considerations1. Positive Impact ✅
2. Production Bundle SizeQuestion: Has the production bundle size been compared between Babel and SWC output? Recommendation: Add to PR description: # Before (Babel)
RAILS_ENV=production bundle exec rake shakapacker:compile
du -sh public/packs
# After (SWC)
RAILS_ENV=production bundle exec rake shakapacker:compile
du -sh public/packs3. Runtime PerformanceThe transpiled code should have similar runtime performance, but worth validating that:
Test Coverage Concerns1. Missing Test: Verify PropTypes StrippingIssue: The PR mentions SWC automatically strips PropTypes in production, but no test validates this. Recommendation: Add a test in # spec/webpack/swc_config_spec.rb
RSpec.describe 'SWC Configuration' do
it 'strips PropTypes in production builds' do
ENV['NODE_ENV'] = 'production'
# Compile a component with PropTypes
# Check output doesn't contain PropTypes
end
end2. Missing Test: Fast RefreshRecommendation: Add integration test for HMR/Fast Refresh functionality. 3. No Regression Tests for CSS ModulesThe PR mentions CSS Modules are handled by webpack, but given previous Shakapacker issues with CSS Modules, explicit tests would be valuable. 🎯 Additional Recommendations1. Add Migration Checklist to PR TemplateConsider adding to ## For Build System Changes
- [ ] Tested in development mode
- [ ] Tested in production mode
- [ ] Verified HMR/Fast Refresh works
- [ ] Compared bundle sizes
- [ ] Updated relevant documentation2. Consider TypeScript ConfigThe SWC config only handles ECMAScript. Add TypeScript example: // For TypeScript files, use:
jsc: {
parser: {
syntax: 'typescript',
tsx: true,
dynamicImport: true,
},
// ... rest of config
}3. Knip ConfigurationGood addition to ignore SWC deps! Consider also adding: // For projects that might have both
ignoreDependencies: [
'@swc/core',
'swc-loader',
'@babel/core',
'babel-loader'
],📋 Pre-Merge ChecklistBefore merging, please verify:
🎉 Overall AssessmentThis is a high-quality PR with excellent documentation and a smart migration strategy. The gradual approach (SWC for standard, Babel for RSC) demonstrates good engineering judgment. Rating: 8.5/10 Main blockers before merge:
Nice-to-haves:
Great work on this migration! The performance benefits will significantly improve developer experience. 🚀 |
- Add error handling to swc.config.js for missing shakapacker - Add Prerequisites section documenting Shakapacker 9.0+ requirement - Expand Troubleshooting section with additional common issues: - Build fails with missing @swc/core - Fast Refresh not working - Syntax errors not being caught - TypeScript files not transpiling - Update config examples in documentation to include error handling - Add eslint-disable for global-require (necessary for error handling) These improvements make the migration guide more robust and help users debug common SWC configuration issues.
Response to Code ReviewThanks for the detailed review! I've addressed the key issues: ✅ Addressed
📝 Clarification on Shakapacker VersionThe Shakapacker 9.1.0 version is NOT part of this PR. It was already upgraded to 9.1.0 on master in PR #1921. This PR only adds SWC configuration on top of the existing Shakapacker 9.1.0 setup. My branch commits (from ):
🔍 Regarding Other SuggestionsPerformance benchmarks: While "~20x faster" is a general SWC claim, actual benchmarks would vary significantly by project size and machine specs. I've kept the claim but haven't added specific numbers as they could be misleading. Bundle size comparison: Good suggestion for future work, but since this is demonstrating SWC compatibility rather than a production deployment, I've focused on build time improvements. Test coverage for PropTypes stripping: Excellent suggestion! This could be a follow-up PR to add comprehensive webpack output tests. Thanks again for the thorough review! 🙏 |
PR Review: Migrate from Babel to SWC for faster JavaScript transpilationSummaryThis PR successfully migrates the standard dummy app ( ✅ Strengths1. Excellent Documentation
2. Sound Technical Approach
3. Configuration Quality
🔍 Code Quality ObservationsSWC Configuration (
|
Code Review: Migrate from Babel to SWC for faster JavaScript transpilationThanks for this well-documented PR! This is a thoughtful migration that demonstrates a pragmatic approach to adopting faster build tooling. Here's my comprehensive review: ✅ Strengths1. Excellent Documentation
2. Smart Gradual Migration Strategy
3. Proper Configuration
4. Knip Configuration Updates
5. Test Coverage
🔍 Issues & Recommendations1. Missing: PropTypes Removal Configuration
|
Pull Request Review: Babel to SWC MigrationOverviewThis PR successfully demonstrates the migration from Babel to SWC in the standard dummy app while maintaining stability for RSC features in the Pro version. The approach is well-thought-out and demonstrates responsible technology adoption. ✅ Strengths1. Excellent Documentation
2. Prudent Technical Approach
3. Configuration QualityThe swc.config.js is well-structured with error handling, environment-aware configuration, keepClassNames for Stimulus compatibility, React automatic runtime with Fast Refresh support, and modern browser targets. 4. Proper Tooling Updates
🔍 Areas for Improvement1. Testing & ValidationMISSING: CI check evidence
Edge Cases to Test:
2. Documentation EnhancementsIMPORTANT: Add rollback instructions The migration guide should include steps to revert to Babel if issues arise. NICE-TO-HAVE: Real performance benchmarks
3. Pre-Merge Requirements (per CLAUDE.md)CRITICAL: CHANGELOG.md update required
VERIFY: Trailing newlines
MANDATORY: RuboCop must pass
🔒 Security Assessment✅ No security concerns identified
⚡ Performance ConsiderationsStrengths:
Recommendation:
📋 Pre-Merge ChecklistMust complete before merge:
🎯 Recommendations SummaryMUST FIX (Before Merge):
SHOULD CONSIDER:
NICE TO HAVE:
🏆 Overall AssessmentStatus: ✅ APPROVE WITH MINOR REVISIONS This is a high-quality PR demonstrating excellent engineering judgment, comprehensive documentation, responsible technology adoption, and zero breaking changes. The migration strategy is sound. Main blockers are standard pre-merge requirements (CI, CHANGELOG, linting). Impact: Significant developer experience improvement with faster builds and HMR while maintaining stability for RSC features. Great work on the gradual migration approach and thorough documentation! Review performed by Claude Code following React on Rails conventions from CLAUDE.md |
Summary
This PR switches the JavaScript transpiler from Babel to SWC (Speedy Web Compiler) in the standard dummy app (
spec/dummy), providing approximately 20x faster compilation times. The Pro dummy app (react_on_rails_pro/spec/dummy) continues using Babel for React Server Components stability.Key Changes
@swc/coreandswc-loaderdependenciesspec/dummyspec/dummy/config/shakapacker.ymlto use SWCreact_on_rails_pro/spec/dummyusing Babel (RSC stability)docs/swc-migration.md)Performance Improvements
Approach: Gradual Migration
This PR demonstrates a safe, gradual migration strategy:
Standard dummy app (
spec/dummy): ✅ Uses SWCPro dummy app (⚠️ Stays with Babel
react_on_rails_pro/spec/dummy):React Server Components Compatibility
Based on extensive research and testing:
docs/swc-migration.mdDocumentation
Created comprehensive migration guide covering:
Testing
Test Coverage
All features tested successfully with SWC in spec/dummy:
Breaking Changes
None. This is a demonstration/validation PR showing SWC works with React on Rails core features.
Migration Path for Users
Users can migrate by following the guide in
docs/swc-migration.md:yarn add -D @swc/core swc-loaderconfig/shakapacker.yml: Setjavascript_transpiler: swcconfig/swc.config.jswith configurationRecommendation:
Benefits of This Approach
🤖 Generated with Claude Code
This change is
Summary by CodeRabbit
Documentation
New Features