Skip to content

Commit bc69dcd

Browse files
justin808claude
andcommitted
Fix React on Rails v15 generator and restore colorized output
- Restore colorized URLs in bin/dev help and generator messages after revert - Fix pack generator template to use single HelloWorld.jsx component - Remove client/server split in favor of simpler component structure - Update generator to create unified component with documentation - Fix ESLint and RuboCop style issues 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3750762 commit bc69dcd

File tree

9 files changed

+268
-133
lines changed

9 files changed

+268
-133
lines changed

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.2)
10+
shakapacker (~> 8.0)
1111

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

TODO.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# React on Rails TODO
2+
3+
## Generator Improvements
4+
5+
### HelloWorld Component Structure
6+
- [x] Fix bad import in HelloWorld.server.jsx (server importing from client)
7+
- [x] Simplify to single HelloWorld.jsx file with documentation
8+
- [ ] **Consider alternative approach**: Create second example component showing client/server split
9+
- Add `client_server_different.jsx` in sibling directory like `/examples/` or `/advanced/`
10+
- Show real-world use case (React Router, styled-components, etc.)
11+
- Keep HelloWorld simple for beginners
12+
13+
### File Organization
14+
- [x] **Improved ror_components directory structure**
15+
- Documentation now suggests moving shared components to `../components/` directory
16+
- Keeps ror_components clean for React on Rails specific entry points
17+
- Recommended structure:
18+
```
19+
src/HelloWorld/
20+
├── components/
21+
│ └── HelloWorld.jsx # Shared component implementation
22+
└── ror_components/
23+
├── HelloWorld.client.jsx # Client entry point (when needed)
24+
└── HelloWorld.server.jsx # Server entry point (when needed)
25+
```
26+
- [ ] **Consider adding generator flag to create this structure automatically**
27+
28+
### Generator Options
29+
- [ ] **Add generator flags for different patterns**
30+
- `--simple` (default): Single component file
31+
- `--split`: Generate client/server split example
32+
- `--example-name`: Customize component name beyond HelloWorld
33+
34+
## Documentation Improvements
35+
36+
### Component Architecture Guide
37+
- [ ] **Add comprehensive docs on client/server patterns**
38+
- When to use single vs split files
39+
- Common libraries requiring server setup (React Router, styled-components, Apollo)
40+
- Migration path from simple to split architecture
41+
- Auto-registration behavior explanation
42+
43+
### Code Comments
44+
- [x] Add inline documentation to HelloWorld.jsx explaining split pattern
45+
- [ ] Add JSDoc comments for better IDE support
46+
- [ ] Include links to relevant documentation sections
47+
48+
## Testing Infrastructure
49+
- [ ] **Test generator output for both simple and split patterns**
50+
- [ ] **Validate that auto-registration works correctly**
51+
- [ ] **Add integration tests for client/server rendering differences**
52+
53+
## Developer Experience
54+
- [ ] **bin/dev help command enhancements**
55+
- [x] Add emojis and colors for better readability
56+
- [ ] Add section about component development patterns
57+
- [ ] Include troubleshooting for client/server split issues
58+
59+
- [ ] **Babel Configuration Conflict Detection**
60+
- [ ] Add validation in generator/initializer to detect conflicting Babel configs
61+
- [ ] Improve error messaging for duplicate preset issues
62+
- [ ] Common conflict: babel.config.js + package.json "babel" section
63+
- [ ] Specific guidance for yalc development workflow
64+
- [ ] Add troubleshooting section for this common issue:
65+
```
66+
❌ BABEL CONFIGURATION CONFLICT DETECTED
67+
Found duplicate Babel configurations:
68+
• babel.config.js ✓ (recommended)
69+
• package.json "babel" section ❌ (conflicting)
70+
71+
🔧 FIX: Remove the "babel" section from package.json
72+
```
73+
74+
### IDE Support
75+
- [ ] **Improve TypeScript support**
76+
- Add .d.ts files for better type inference
77+
- Document TypeScript patterns for client/server split
78+
- Consider TypeScript generator templates
79+
80+
## Performance & Bundle Analysis
81+
- [ ] **Bundle splitting documentation**
82+
- How React on Rails handles client/server bundles
83+
- Best practices for code splitting
84+
- webpack bundle analysis guidance
85+
86+
## Real-World Examples
87+
- [ ] **Create example apps showing advanced patterns**
88+
- React Router with SSR
89+
- styled-components with server-side rendering
90+
- Apollo Client hydration
91+
- Next.js-style patterns
92+
93+
## Migration Guide
94+
- [ ] **Document upgrade paths**
95+
- Converting from Webpacker to Shakapacker
96+
- Migrating from single to split components
97+
- Updating existing projects to new patterns
98+
99+
## Community & Ecosystem
100+
- [ ] **Plugin ecosystem considerations**
101+
- Standard patterns for community components
102+
- Guidelines for React on Rails compatible libraries
103+
- Template repository for component patterns
104+
105+
---
106+
107+
## Current Known Issues
108+
- Generator installer still has remaining issues (mentioned in context)
109+
- Version mismatch warnings with yalc during development
110+
- Need clearer documentation on when to use different patterns
111+
- **Babel configuration conflicts** - Common during yalc development when package.json and babel.config.js both define presets
112+
113+
## Priority Order
114+
1. Fix remaining generator installer issues
115+
2. Improve HelloWorld component documentation
116+
3. Add alternative example showing client/server split
117+
4. Create comprehensive architecture documentation
118+
5. Add generator flags for different patterns

lib/generators/react_on_rails/generator_messages.rb

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -46,39 +46,37 @@ def helpful_message_after_installation(component_name: "HelloWorld")
4646

4747
<<~MSG
4848
49-
╔════════════════════════════════════════════════════════════════════════╗
50-
║ 🎉 React on Rails Successfully Installed! ║
51-
╚════════════════════════════════════════════════════════════════════════╝
52-
53-
📋 QUICK START:
54-
─────────────────────────────────────────────────────────────────────────
55-
1. Install dependencies:
56-
#{Rainbow("bundle && #{package_manager} install").cyan}
57-
58-
2. Start the app:
59-
./bin/dev # HMR (Hot Module Replacement) mode
60-
./bin/dev static # Static bundles (no HMR, faster initial load)
61-
./bin/dev prod # Production-like mode for testing
62-
./bin/dev help # See all available options
63-
#{process_manager_section}
64-
65-
3. Visit: http://localhost:3000/hello_world
66-
#{shakapacker_status}
67-
✨ KEY FEATURES:
68-
─────────────────────────────────────────────────────────────────────────
69-
• Auto-registration enabled - Your layout only needs:
70-
<%= javascript_pack_tag %>
71-
<%= stylesheet_pack_tag %>
72-
73-
• Server-side rendering - Enable it in app/views/hello_world/index.html.erb:
74-
<%= react_component("#{component_name}", props: @hello_world_props, prerender: true) %>
75-
76-
📚 LEARN MORE:
77-
─────────────────────────────────────────────────────────────────────────
78-
• Documentation: https://www.shakacode.com/react-on-rails/docs/
79-
• Webpack customization: https://github.com/shakacode/shakapacker#webpack-configuration
80-
81-
💡 TIP: Run 'bin/dev help' for development server options and troubleshooting#{testing_section}
49+
╔════════════════════════════════════════════════════════════════════════╗
50+
║ 🎉 React on Rails Successfully Installed! ║
51+
╚════════════════════════════════════════════════════════════════════════╝
52+
#{process_manager_section}#{shakapacker_status}
53+
📋 QUICK START:
54+
─────────────────────────────────────────────────────────────────────────
55+
1. Install dependencies:
56+
#{Rainbow("bundle && #{package_manager} install").cyan}
57+
58+
2. Start the app:
59+
./bin/dev # HMR (Hot Module Replacement) mode
60+
./bin/dev static # Static bundles (no HMR, faster initial load)
61+
./bin/dev prod # Production-like mode for testing
62+
./bin/dev help # See all available options
63+
64+
3. Visit: #{Rainbow('http://localhost:3000/hello_world').cyan.underline}
65+
✨ KEY FEATURES:
66+
─────────────────────────────────────────────────────────────────────────
67+
• Auto-registration enabled - Your layout only needs:
68+
<%= javascript_pack_tag %>
69+
<%= stylesheet_pack_tag %>
70+
71+
• Server-side rendering - Enabled with prerender option in app/views/hello_world/index.html.erb:
72+
<%= react_component("#{component_name}", props: @hello_world_props, prerender: true) %>
73+
74+
📚 LEARN MORE:
75+
─────────────────────────────────────────────────────────────────────────
76+
• Documentation: #{Rainbow('https://www.shakacode.com/react-on-rails/docs/').cyan.underline}
77+
• Webpack customization: #{Rainbow('https://github.com/shakacode/shakapacker#webpack-configuration').cyan.underline}
78+
79+
💡 TIP: Run 'bin/dev help' for development server options and troubleshooting#{testing_section}
8280
MSG
8381
end
8482

@@ -112,12 +110,12 @@ def build_testing_section
112110
<<~TESTING
113111
114112
115-
🧪 TESTING SETUP (Optional):
116-
─────────────────────────────────────────────────────────────────────────
117-
For JavaScript testing with asset compilation, add this to your RSpec config:
113+
🧪 TESTING SETUP (Optional):
114+
─────────────────────────────────────────────────────────────────────────
115+
For JavaScript testing with asset compilation, add this to your RSpec config:
118116
119-
# In spec/rails_helper.rb or spec/spec_helper.rb:
120-
ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
117+
# In spec/rails_helper.rb or spec/spec_helper.rb:
118+
ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
121119
TESTING
122120
end
123121

lib/generators/react_on_rails/react_no_redux_generator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class ReactNoReduxGenerator < Rails::Generators::Base
1313

1414
def copy_base_files
1515
base_js_path = "base/base"
16-
base_files = %w[app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx
17-
app/javascript/src/HelloWorld/ror_components/HelloWorld.server.jsx]
16+
base_files = %w[app/javascript/src/HelloWorld/ror_components/HelloWorld.jsx
17+
app/javascript/src/HelloWorld/ror_components/HelloWorld.module.css]
1818
base_files.each { |file| copy_file("#{base_js_path}/#{file}", file) }
1919
end
2020

lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React, { useState } from 'react';
2+
import * as style from './HelloWorld.module.css';
3+
4+
// This component works for both client and server rendering.
5+
//
6+
// For cases where you need different client/server behavior (e.g., React Router,
7+
// styled-components, or conditional hydration), create separate files:
8+
//
9+
// 1. Move this component to ../components/HelloWorld.jsx
10+
// 2. Create HelloWorld.client.jsx:
11+
// import HelloWorld from '../components/HelloWorld';
12+
// // Add client-specific setup (Router, providers, etc.)
13+
// export default HelloWorld;
14+
//
15+
// 3. Create HelloWorld.server.jsx:
16+
// import HelloWorld from '../components/HelloWorld';
17+
// // Add server-specific setup (StaticRouter, etc.)
18+
// export default HelloWorld;
19+
//
20+
// React on Rails will auto-register both .client and .server versions.
21+
22+
const HelloWorld = (props) => {
23+
const [name, setName] = useState(props.name);
24+
25+
return (
26+
<div>
27+
<h3>Hello, {name}!</h3>
28+
<hr />
29+
<form>
30+
<label className={style.bright} htmlFor="name">
31+
Say hello to:
32+
<input id="name" type="text" value={name} onChange={(e) => setName(e.target.value)} />
33+
</label>
34+
</form>
35+
</div>
36+
);
37+
};
38+
39+
export default HelloWorld;

lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.server.jsx

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)