Skip to content

Commit ed3bda3

Browse files
justin808claude
andcommitted
Improve Shakapacker compatibility and add autofix command
- Lower Shakapacker requirement from ~> 8.0 to >= 6.0 for broader compatibility - Add intelligent version warning in generator output for Shakapacker < 8.0 - Create unified autofix command (rake autofix) combining eslint --fix, prettier --write, and rubocop -A - Update AI agent best practices documentation with simplified workflow - Add prettier --write to linting workflow for complete formatting coverage The version strategy maintains backward compatibility while encouraging upgrades through clear messaging and actionable guidance. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent a9a7732 commit ed3bda3

File tree

8 files changed

+101
-27
lines changed

8 files changed

+101
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Changes since the last non-beta release.
3636
- Removed files: `rakelib/webpacker_examples.rake`, `lib/generators/react_on_rails/adapt_for_older_shakapacker_generator.rb`
3737
- All webpacker compatibility code and tests have been removed
3838
- **CI/Development runtime requirements updated**:
39-
- *Note, this is just what CI tests*. You can use older versions of Ruby and Node.js, but you may run into issues.*
39+
- _Note, this is just what CI tests_. You can use older versions of Ruby and Node.js, but you may run into issues.\*
4040
- Minimum Ruby version: 3.2 (was 3.0)
4141
- Maximum Ruby version: 3.4 (was 3.3)
4242
- Minimum Node.js version: 20 (was 16)

CONTRIBUTING.md

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ git clean -fd && git reset --hard && git clean -fd
292292
When testing specific generator improvements or fixes, test both Shakapacker scenarios:
293293

294294
**Scenario A: No Shakapacker installed (fresh Rails app)**
295+
295296
```bash
296297
# Reset to clean baseline before each test
297298
git clean -fd && git reset --hard generator_testing_base && git clean -fd
@@ -307,6 +308,7 @@ rails generate react_on_rails:install
307308
```
308309

309310
**Scenario B: Shakapacker already installed**
311+
310312
```bash
311313
# Reset to clean baseline
312314
git clean -fd && git reset --hard generator_testing_base && git clean -fd
@@ -330,10 +332,11 @@ rails generate react_on_rails:install
330332
**3. Document testing results:**
331333

332334
For each commit tested, document:
335+
333336
- Generator execution success/failure for both scenarios
334337
- Shakapacker installation/detection behavior
335338
- Component rendering in browser
336-
- Console output and warnings
339+
- Console output and warnings
337340
- File generation differences between scenarios
338341
- Specific issues found
339342

@@ -355,7 +358,7 @@ When testing specific commits that fix generator issues, follow this process:
355358
cd ~/shakacode/react-on-rails/react_on_rails
356359
git checkout <commit-hash> # e.g., 81c66fa or bc69dcd0
357360

358-
# In test application
361+
# In test application
359362
cd ~/shakacode/react-on-rails/react_on_rails-test-apps/react-on-rails-tutorial-v15
360363

361364
# Reset to clean baseline
@@ -370,6 +373,7 @@ bundle install
370373
```
371374

372375
**Expected outcomes to verify:**
376+
373377
- Generator completes without errors
374378
- Shakapacker integration works correctly
375379
- React components render and are interactive
@@ -420,22 +424,26 @@ npm install ../path/to/react_on_rails/react-on-rails-15.0.0.tgz
420424
```
421425

422426
This approach:
427+
423428
- ✅ Exactly mimics real package installation
424-
- ✅ No symlink issues across different filesystems
429+
- ✅ No symlink issues across different filesystems
425430
- ✅ More reliable for CI/CD testing
426431
- ⚠️ Requires manual step after each change (can be scripted)
427432

428433
**Why this is needed**:
434+
429435
- The gem provides Rails integration and server-side rendering
430436
- Yalc provides the complete JavaScript client library needed for component mounting
431437
- Without yalc, you'll see empty divs where React components should render
432438

433439
**Verification**:
440+
434441
- Visit the hello_world page in browser
435442
- Check browser console for "RENDERED HelloWorld to dom node" success message
436443
- Confirm React component is interactive (input field updates name display)
437444

438445
**Development Mode Console Output**:
446+
439447
- `bin/dev` (HMR): Shows HMR warnings and resource preload warnings (expected)
440448
- `bin/dev static`: Shows only resource preload warnings (cleaner output)
441449
- `bin/dev prod`: Cleanest output with minimal warnings (production-like environment)
@@ -447,18 +455,22 @@ This approach:
447455
**Common Issues and Solutions:**
448456

449457
1. **React components not rendering (empty divs)**
458+
450459
- **Cause**: Missing yalc setup for JavaScript package
451460
- **Solution**: Follow yalc setup steps above after running generator
452461

453462
2. **Generator fails with Shakapacker errors**
463+
454464
- **Cause**: Conflicting Shakapacker versions or incomplete installation
455465
- **Solution**: Clean reset and ensure consistent Shakapacker version across tests
456466

457467
3. **Babel configuration conflicts during yalc development**
468+
458469
- **Cause**: Both `babel.config.js` and `package.json` "babel" section defining presets
459470
- **Solution**: Remove "babel" section from `package.json`, keep only `babel.config.js`
460471

461472
4. **"Package.json not found" errors**
473+
462474
- **Cause**: Generator trying to access non-existent package.json files
463475
- **Solution**: Test with commits that fix this specific issue (e.g., bc69dcd0)
464476

@@ -467,6 +479,7 @@ This approach:
467479
- **Solution**: Run `bin/dev kill` before starting new test servers
468480

469481
**Testing Best Practices:**
482+
470483
- Always use the double clean command: `git clean -fd && git reset --hard && git clean -fd`
471484
- Test both Shakapacker scenarios for comprehensive coverage
472485
- Document exact error messages and steps to reproduce
@@ -495,6 +508,7 @@ rake lint
495508
```
496509

497510
**Automated checks:**
511+
498512
- Format all JavaScript/TypeScript files with Prettier
499513
- Check and fix linting issues with ESLint
500514
- Check and fix Ruby style issues with RuboCop
@@ -506,53 +520,46 @@ rake lint
506520

507521
**CRITICAL WORKFLOW** to prevent CI failures:
508522

509-
### 1. **ALWAYS Lint Before Any Code Changes**
510-
```bash
511-
# First, check current state
512-
rake lint
523+
### 1. **After Making Code Changes**
513524

514-
# If violations exist, auto-fix them first
515-
yarn run eslint . --fix # Auto-fix JS/TS formatting
516-
bundle exec rubocop -A # Auto-fix Ruby violations
517-
```
518-
519-
### 2. **After Making Code Changes**
520525
```bash
521-
# MANDATORY: Run linters again
526+
# MANDATORY: Run linters after code changes
522527
rake lint
523528

524529
# If any violations, auto-fix immediately
525-
yarn run eslint . --fix
526-
bundle exec rubocop -A
530+
rake autofix # One command to run all auto-fixes
527531

528532
# Verify everything passes
529533
rake lint
530534
```
531535

532-
### 3. **Common AI Agent Mistakes**
536+
### 2. **Common AI Agent Mistakes**
533537

534538
**DON'T:**
535-
- Make code changes without running linters first
539+
536540
- Commit code that hasn't been linted locally
537541
- Ignore formatting rules when creating new files
538542
- Add manual formatting that conflicts with Prettier/RuboCop
539543

540544
**DO:**
541-
- Run `rake lint` before AND after any code changes
542-
- Use auto-fix options (`--fix`, `-A`) to resolve violations
545+
546+
- Run `rake lint` after any code changes
547+
- Use `rake autofix` to automatically fix all linting violations
543548
- Create new files that follow existing patterns
544549
- Test locally before committing
545550

546551
### 4. **Template File Best Practices**
547552

548553
When creating new template files (`.jsx`, `.rb`, etc.):
554+
549555
1. Copy existing template structure and patterns
550556
2. Run `yarn run eslint . --fix` immediately after creation
551557
3. Verify with `rake lint` before committing
552558

553559
### 5. **RuboCop Complexity Issues**
554560

555561
For methods with high ABC complexity (usually formatting/display methods):
562+
556563
```ruby
557564
# rubocop:disable Metrics/AbcSize
558565
def complex_formatting_method

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PATH
77
execjs (~> 2.5)
88
rails (>= 5.2)
99
rainbow (~> 3.0)
10-
shakapacker (~> 8.0)
10+
shakapacker (>= 6.0)
1111

1212
GEM
1313
remote: https://rubygems.org/

TODO.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Generator Improvements
44

55
### HelloWorld Component Structure
6+
67
- [x] Fix bad import in HelloWorld.server.jsx (server importing from client)
78
- [x] Simplify to single HelloWorld.jsx file with documentation
89
- [ ] **Consider alternative approach**: Create second example component showing client/server split
@@ -11,6 +12,7 @@
1112
- Keep HelloWorld simple for beginners
1213

1314
### File Organization
15+
1416
- [x] **Improved ror_components directory structure**
1517
- Documentation now suggests moving shared components to `../components/` directory
1618
- Keeps ror_components clean for React on Rails specific entry points
@@ -26,6 +28,7 @@
2628
- [ ] **Consider adding generator flag to create this structure automatically**
2729
2830
### Generator Options
31+
2932
- [ ] **Add generator flags for different patterns**
3033
- `--simple` (default): Single component file
3134
- `--split`: Generate client/server split example
@@ -34,34 +37,41 @@
3437
## Documentation Improvements
3538
3639
### Component Architecture Guide
40+
3741
- [ ] **Add comprehensive docs on client/server patterns**
3842
- When to use single vs split files
3943
- Common libraries requiring server setup (React Router, styled-components, Apollo)
4044
- Migration path from simple to split architecture
4145
- Auto-registration behavior explanation
4246
4347
### Code Comments
48+
4449
- [x] Add inline documentation to HelloWorld.jsx explaining split pattern
4550
- [ ] Add JSDoc comments for better IDE support
4651
- [ ] Include links to relevant documentation sections
4752
4853
## Testing Infrastructure
54+
4955
- [ ] **Test generator output for both simple and split patterns**
5056
- [ ] **Validate that auto-registration works correctly**
5157
- [ ] **Add integration tests for client/server rendering differences**
5258
5359
## Developer Experience
60+
5461
- [ ] **bin/dev help command enhancements**
62+
5563
- [x] Add emojis and colors for better readability
5664
- [ ] Add section about component development patterns
5765
- [ ] Include troubleshooting for client/server split issues
5866
5967
- [ ] **Babel Configuration Conflict Detection**
68+
6069
- [ ] Add validation in generator/initializer to detect conflicting Babel configs
6170
- [ ] Improve error messaging for duplicate preset issues
6271
- [ ] Common conflict: babel.config.js + package.json "babel" section
6372
- [ ] Specific guidance for yalc development workflow
6473
- [ ] Add troubleshooting section for this common issue:
74+
6575
```
6676
❌ BABEL CONFIGURATION CONFLICT DETECTED
6777
Found duplicate Babel configurations:
@@ -72,31 +82,36 @@
7282
```
7383
7484
### IDE Support
85+
7586
- [ ] **Improve TypeScript support**
7687
- Add .d.ts files for better type inference
7788
- Document TypeScript patterns for client/server split
7889
- Consider TypeScript generator templates
7990
8091
## Performance & Bundle Analysis
92+
8193
- [ ] **Bundle splitting documentation**
8294
- How React on Rails handles client/server bundles
8395
- Best practices for code splitting
8496
- webpack bundle analysis guidance
8597
8698
## Real-World Examples
99+
87100
- [ ] **Create example apps showing advanced patterns**
88101
- React Router with SSR
89102
- styled-components with server-side rendering
90103
- Apollo Client hydration
91104
- Next.js-style patterns
92105
93106
## Migration Guide
107+
94108
- [ ] **Document upgrade paths**
95109
- Converting from Webpacker to Shakapacker
96110
- Migrating from single to split components
97111
- Updating existing projects to new patterns
98112
99113
## Community & Ecosystem
114+
100115
- [ ] **Plugin ecosystem considerations**
101116
- Standard patterns for community components
102117
- Guidelines for React on Rails compatible libraries
@@ -105,14 +120,16 @@
105120
---
106121
107122
## Current Known Issues
123+
108124
- Generator installer still has remaining issues (mentioned in context)
109125
- Version mismatch warnings with yalc during development
110126
- Need clearer documentation on when to use different patterns
111127
- **Babel configuration conflicts** - Common during yalc development when package.json and babel.config.js both define presets
112128
113129
## Priority Order
130+
114131
1. Fix remaining generator installer issues
115132
2. Improve HelloWorld component documentation
116133
3. Add alternative example showing client/server split
117134
4. Create comprehensive architecture documentation
118-
5. Add generator flags for different patterns
135+
5. Add generator flags for different patterns

lib/generators/react_on_rails/generator_messages.rb

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,55 @@ def detect_process_manager
129129
end
130130

131131
def build_shakapacker_status_section
132+
version_warning = check_shakapacker_version_warning
133+
132134
if File.exist?(".shakapacker_just_installed")
133-
<<~SHAKAPACKER
135+
base_message = <<~SHAKAPACKER
134136
135137
📦 SHAKAPACKER SETUP:
136138
─────────────────────────────────────────────────────────────────────────
137139
#{Rainbow('✓ Added to Gemfile automatically').green}
138140
#{Rainbow('✓ Installer ran successfully').green}
139141
#{Rainbow('✓ Webpack integration configured').green}
140142
SHAKAPACKER
143+
base_message + version_warning
141144
elsif File.exist?("bin/shakapacker") && File.exist?("bin/shakapacker-dev-server")
142-
"\n📦 #{Rainbow('Shakapacker already configured ✓').green}"
145+
"\n📦 #{Rainbow('Shakapacker already configured ✓').green}#{version_warning}"
146+
else
147+
"\n📦 #{Rainbow('Shakapacker setup may be incomplete').yellow}#{version_warning}"
148+
end
149+
end
150+
151+
def check_shakapacker_version_warning
152+
# Try to detect Shakapacker version from Gemfile.lock
153+
return "" unless File.exist?("Gemfile.lock")
154+
155+
gemfile_lock_content = File.read("Gemfile.lock")
156+
shakapacker_match = gemfile_lock_content.match(/shakapacker \((\d+\.\d+\.\d+)\)/)
157+
158+
return "" unless shakapacker_match
159+
160+
version = shakapacker_match[1]
161+
major_version = version.split(".").first.to_i
162+
163+
if major_version < 8
164+
<<~WARNING
165+
166+
⚠️ #{Rainbow('IMPORTANT: Upgrade Recommended').yellow.bold}
167+
─────────────────────────────────────────────────────────────────────────
168+
You are using Shakapacker #{version}. React on Rails v15+ works best with
169+
Shakapacker 8.0+ for optimal Hot Module Replacement and build performance.
170+
171+
To upgrade: #{Rainbow('bundle update shakapacker').cyan}
172+
173+
Learn more: #{Rainbow('https://github.com/shakacode/shakapacker').cyan.underline}
174+
WARNING
143175
else
144-
"\n📦 #{Rainbow('Shakapacker setup may be incomplete').yellow}"
176+
""
145177
end
178+
rescue StandardError
179+
# If version detection fails, don't show a warning to avoid noise
180+
""
146181
end
147182

148183
def detect_package_manager

package-scripts.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ scripts:
3838
description: Check that all files were formatted using prettier.
3939
script: prettier --check .
4040

41+
autofix:
42+
description: Auto-fix all linting violations (eslint --fix, prettier --write, rubocop -A).
43+
script: rake autofix
44+
4145
renderer:
4246
description: Starts the node renderer.
4347
script: node renderer.js

0 commit comments

Comments
 (0)