Skip to content

Commit 99044da

Browse files
justin808claude
andcommitted
Enhance documentation and error handling for v16.0.0 release
- Add comprehensive v16 upgrade instructions to README and upgrade guide - Reorganize CHANGELOG with clearer v16.0.0 breaking changes and migration steps - Enhance generate_packs rake task with detailed error handling and debugging guidance - Extract error handling methods to improve code maintainability - Add context-specific solutions for common component generation errors - Improve RuboCop compliance with extracted methods and disable pragmas 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 1b0830d commit 99044da

File tree

5 files changed

+240
-11
lines changed

5 files changed

+240
-11
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ See [Release Notes](docs/release-notes/16.0.0.md) for complete migration guide.
3232
#### Major Enhancements
3333

3434
**🚀 React Server Components (RSC) -- Requires React on Rails Pro**
35+
3536
- **Enhanced RSC rendering flow**: Eliminated double rendering and reduced HTTP requests
3637
- **`RSCRoute` component**: Seamless server-side rendering with automatic payload injection and hydration [PR 1696](https://github.com/shakacode/react_on_rails/pull/1696) by [AbanoubGhadban](https://github.com/AbanoubGhadban)
3738
- **Optimized RSC payload injection**: Now injected after component HTML markup for better performance [PR 1738](https://github.com/shakacode/react_on_rails/pull/1738) by [AbanoubGhadban](https://github.com/AbanoubGhadban)
3839
- **Communication protocol v2.0.0**: Supports uploading multiple bundles at once for improved efficiency
3940

4041
**⚡ Performance & Loading Strategy**
42+
4143
- **New `generated_component_packs_loading_strategy`**: Choose from `sync`, `async`, or `defer` strategies [PR 1712](https://github.com/shakacode/react_on_rails/pull/1712) by [AbanoubGhadban](https://github.com/AbanoubGhadban)
4244
- **Async render function support**: Components can now return from async render functions [PR 1720](https://github.com/shakacode/react_on_rails/pull/1720) by [AbanoubGhadban](https://github.com/AbanoubGhadban)
4345
- **Optimized client imports**: Generated packs now import from `react-on-rails/client` for better tree-shaking [PR 1706](https://github.com/shakacode/react_on_rails/pull/1706) by [alexeyr-ci](https://github.com/alexeyr-ci)
@@ -50,10 +52,10 @@ See [Release Notes](docs/release-notes/16.0.0.md) for complete migration guide.
5052
- **ReactRefreshWebpackPlugin v0.6.0 support**: Added conditional logic for proper configuration [PR 1748](https://github.com/shakacode/react_on_rails/pull/1748) by [judahmeek](https://github.com/judahmeek)
5153
- **Version validation improvements**: Fixed invalid warnings with pre-release versions [PR 1742](https://github.com/shakacode/react_on_rails/pull/1742) by [alexeyr-ci2](https://github.com/alexeyr-ci2)
5254

53-
5455
#### Breaking Changes
5556

5657
**🔧 Webpacker Support Removed**
58+
5759
- **Complete removal of Webpacker support**. Shakapacker >= 6.0 is now required.
5860
- Migration:
5961
- Remove `webpacker` gem from your Gemfile
@@ -63,15 +65,18 @@ See [Release Notes](docs/release-notes/16.0.0.md) for complete migration guide.
6365
- Removed files: `rakelib/webpacker_examples.rake`, `lib/generators/react_on_rails/adapt_for_older_shakapacker_generator.rb`
6466

6567
**📦 Package System Modernization**
68+
6669
- **ESM-only package**: CommonJS `require()` no longer supported
6770
- Migration:
6871
- Replace `require('react-on-rails')` with `import ReactOnRails from 'react-on-rails'`
6972
- For Node.js < 20.19.0, upgrade or use dynamic imports
7073
- For TypeScript errors, upgrade to TypeScript 5.8+ and set `module: "nodenext"`
7174

7275
**⚡ Configuration API Changes**
76+
7377
- **`defer_generated_component_packs` deprecated** → use `generated_component_packs_loading_strategy`
7478
- Migration:
79+
7580
- `defer_generated_component_packs: true``generated_component_packs_loading_strategy: :defer`
7681
- `defer_generated_component_packs: false``generated_component_packs_loading_strategy: :sync`
7782
- Recommended: `generated_component_packs_loading_strategy: :async` for best performance
@@ -84,20 +89,22 @@ See [Release Notes](docs/release-notes/16.0.0.md) for complete migration guide.
8489
- Note: `immediate_hydration` requires React on Rails Pro license
8590

8691
**🔄 Async API Changes**
92+
8793
- **`ReactOnRails.reactOnRailsPageLoaded()` is now async**
8894
- Migration: Add `await` when calling: `await ReactOnRails.reactOnRailsPageLoaded()`
8995

9096
**🏗️ Runtime Suggested Versions**
97+
9198
- Ruby: 3.2 - 3.4 (was 3.0 - 3.3)
9299
- Node.js: 20 - 22 (was 16 - 20)
93100
- Note: These are CI-tested versions; older versions may work but aren't guaranteed
94101

95102
**🎯 Generator Improvements**
103+
96104
- Install generator now validates JavaScript package manager presence
97105
- Improved error handling with `Thor::Error` instead of `exit(1)`
98106
- Enhanced error messages with clearer troubleshooting steps
99107

100-
101108
### [15.0.0] - 2025-08-28 - RETRACTED
102109

103110
**⚠️ This version has been retracted due to API design issues. Please upgrade directly to v16.0.0.**

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
react_on_rails (15.0.0)
4+
react_on_rails (16.0.0)
55
addressable
66
connection_pool
77
execjs (~> 2.5)

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,35 @@ We also specialize in helping development teams lower infrastructure and CI cost
4747

4848
If you think ShakaCode can help your project, [click here](https://meetings.hubspot.com/justingordon/30-minute-consultation) to book a call with [Justin Gordon](mailto:[email protected]), the creator of React on Rails.
4949

50+
## Upgrading React on Rails
51+
52+
After upgrading to a new major version, run the generator to get latest defaults:
53+
54+
```bash
55+
rails generate react_on_rails:install
56+
```
57+
58+
**Important**: Review changes carefully before applying to avoid overwriting custom configurations. The generator updates:
59+
60+
- `bin/dev` (improved development workflow)
61+
- webpack configurations
62+
- `shakapacker.yml` settings
63+
- other configuration files
64+
65+
For detailed upgrade instructions, see [upgrade guide documentation](docs/guides/upgrading-react-on-rails.md).
66+
5067
## React on Rails Pro
5168

5269
Some features of React on Rails regarding performance require a React on Rails Pro subscription.
5370

5471
Note: the subscription price is free for evaluation and non-production use.
5572

5673
Notable new features include:
57-
* React Server Components
58-
* Streaming SSR
59-
* Loadable Components
60-
* Code Splitting with React Router
74+
75+
- React Server Components
76+
- Streaming SSR
77+
- Loadable Components
78+
- Code Splitting with React Router
6179

6280
React on Rails Pro is the best way to optimize your Webpack setup for React on Rails, including code splitting with [React Router](https://reactrouter.com/) and [loadable-components](https://loadable-components.com/) with server-side rendering for SEO and hot-reloading for developers.
6381

docs/guides/upgrading-react-on-rails.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,87 @@ If you would like help in migrating between React on Rails versions or help with
66

77
We specialize in helping companies to quickly and efficiently upgrade. The older versions use the Rails asset pipeline to package client assets. The current and recommended way is to use Webpack 4+ for asset preparation. You may also need help migrating from the `rails/webpacker`'s Webpack configuration to a better setup ready for Server Side Rendering.
88

9+
## General Upgrade Process
10+
11+
After upgrading to any major version, always run the generator to get the latest defaults:
12+
13+
```bash
14+
rails generate react_on_rails:install
15+
```
16+
17+
**⚠️ Important**: Review generated changes carefully before applying to avoid overwriting custom configurations. The generator updates:
18+
19+
- `bin/dev` (improved development workflow)
20+
- webpack configurations
21+
- `shakapacker.yml` settings
22+
- other configuration files
23+
24+
## Upgrading to v16
25+
26+
### Breaking Changes
27+
28+
- **Webpacker support completely removed**. Shakapacker >= 6.0 is now required.
29+
- **Updated runtime requirements**:
30+
- Minimum Ruby version: 3.2
31+
- Minimum Node.js version: 20
32+
- **Install generator now validates prerequisites** and requires at least one JavaScript package manager
33+
34+
### Migration Steps
35+
36+
1. **Update Dependencies**
37+
38+
```ruby
39+
# Gemfile
40+
gem "react_on_rails", "~> 16.0"
41+
```
42+
43+
```json
44+
// package.json
45+
{
46+
"dependencies": {
47+
"react-on-rails": "^16.0.0"
48+
}
49+
}
50+
```
51+
52+
2. **Install Updates**
53+
54+
```bash
55+
bundle update react_on_rails
56+
npm install
57+
```
58+
59+
3. **Run Generator**
60+
61+
```bash
62+
rails generate react_on_rails:install
63+
```
64+
65+
4. **Review and Apply Changes**
66+
67+
- Check webpack configuration exports (function naming may have changed)
68+
- Review `shakapacker.yml` settings
69+
- Update `bin/dev` if needed
70+
71+
5. **Test Your Application**
72+
73+
```bash
74+
# Test asset compilation
75+
bundle exec rails assets:precompile
76+
77+
# Test development server
78+
bin/dev
79+
80+
# Run your test suite
81+
bundle exec rspec # or your test command
82+
```
83+
84+
### Enhanced Features in v16
85+
86+
- **Enhanced error handling** in `react_on_rails:generate_packs` task with detailed debugging guidance
87+
- **Improved development tooling** with better error messages and troubleshooting steps
88+
- **Better package manager detection** with multi-strategy validation
89+
990
## Upgrading to v13
1091

1192
### Breaking Change

lib/tasks/generate_packs.rake

Lines changed: 127 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
# rubocop:disable Metrics/BlockLength
34
namespace :react_on_rails do
45
desc <<~DESC
56
If there is a file inside any directory matching config.components_subdirectory, this command generates corresponding packs.
@@ -21,11 +22,133 @@ namespace :react_on_rails do
2122
puts Rainbow("📂 Components subdirectory: #{ReactOnRails.configuration.components_subdirectory}").cyan
2223
puts ""
2324

24-
start_time = Time.now
25-
ReactOnRails::PacksGenerator.instance.generate_packs_if_stale
26-
end_time = Time.now
25+
begin
26+
start_time = Time.now
27+
ReactOnRails::PacksGenerator.instance.generate_packs_if_stale
28+
end_time = Time.now
2729

30+
puts ""
31+
puts Rainbow("✨ Pack generation completed in #{((end_time - start_time) * 1000).round(1)}ms").green
32+
rescue ReactOnRails::Error => e
33+
handle_react_on_rails_error(e)
34+
exit 1
35+
rescue StandardError => e
36+
handle_standard_error(e)
37+
exit 1
38+
end
39+
end
40+
41+
private
42+
43+
# rubocop:disable Metrics/AbcSize
44+
def handle_react_on_rails_error(error)
45+
puts ""
46+
puts Rainbow("❌ REACT ON RAILS ERROR").red.bold
47+
puts Rainbow("=" * 80).red
48+
puts Rainbow("🚨 Pack generation failed with the following error:").red
49+
puts ""
50+
puts Rainbow("📋 ERROR DETAILS:").yellow
51+
puts Rainbow(" Type: #{error.class.name}").white
52+
puts Rainbow(" Message: #{error.message}").white
53+
puts ""
54+
55+
highlight_main_error(error)
56+
show_common_solutions(error)
57+
show_debugging_steps
58+
show_documentation_links
59+
end
60+
# rubocop:enable Metrics/AbcSize
61+
62+
def highlight_main_error(error)
63+
return unless error.message.include?("**ERROR**")
64+
65+
error_lines = error.message.split("\n")
66+
error_lines.each do |line|
67+
next unless line.include?("**ERROR**")
68+
69+
puts Rainbow("🔥 MAIN ISSUE:").red.bold
70+
puts Rainbow(" #{line.gsub('**ERROR**', '').strip}").yellow
71+
end
72+
end
73+
74+
# rubocop:disable Metrics/AbcSize
75+
def show_common_solutions(error)
76+
puts ""
77+
puts Rainbow("💡 COMMON SOLUTIONS:").green.bold
78+
79+
case error.message
80+
when /client specific definition.*overrides the common definition/
81+
puts Rainbow(" • You have both common and client/server specific component files").white
82+
puts Rainbow(" • Delete the common component file (e.g., Component.jsx)").white
83+
puts Rainbow(" • Keep only the client/server specific files " \
84+
"(Component.client.jsx, Component.server.jsx)").white
85+
puts Rainbow(" • See: https://www.shakacode.com/react-on-rails/docs/guides/" \
86+
"file-system-based-automated-bundle-generation.md").cyan
87+
88+
when /Cannot find component/
89+
puts Rainbow(" • Check that your component file exists in the expected location").white
90+
puts Rainbow(" • Verify the component is exported as default export").white
91+
puts Rainbow(" • Ensure the file extension is .jsx or .js").white
92+
93+
when /CSS module.*not found/
94+
puts Rainbow(" • Check that the CSS module file exists").white
95+
puts Rainbow(" • Verify the import path is correct").white
96+
puts Rainbow(" • Ensure all CSS classes referenced in the component exist").white
97+
98+
else
99+
puts Rainbow(" • Check component file structure and naming").white
100+
puts Rainbow(" • Verify all imports and exports are correct").white
101+
puts Rainbow(" • Run with --trace for more detailed error information").white
102+
end
103+
end
104+
# rubocop:enable Metrics/AbcSize
105+
106+
def show_debugging_steps
107+
puts ""
108+
puts Rainbow("🔧 DEBUGGING STEPS:").blue.bold
109+
components_path = "app/javascript/src/**/#{ReactOnRails.configuration.components_subdirectory}/"
110+
puts Rainbow(" 1. Check component files in: #{components_path}").white
111+
puts Rainbow(" 2. Verify component exports: export default ComponentName").white
112+
puts Rainbow(" 3. Check for conflicting common/client/server files").white
113+
puts Rainbow(" 4. Run: rake react_on_rails:generate_packs --trace").white
114+
puts Rainbow(" 5. Check Rails logs for additional details").white
115+
end
116+
117+
def show_documentation_links
118+
puts ""
119+
puts Rainbow("📚 DOCUMENTATION:").magenta.bold
120+
puts Rainbow(" • File-system based components: https://www.shakacode.com/react-on-rails/docs/" \
121+
"guides/file-system-based-automated-bundle-generation.md").cyan
122+
puts Rainbow(" • Component registration: https://www.shakacode.com/react-on-rails/docs/").cyan
123+
puts Rainbow("=" * 80).red
124+
end
125+
126+
# rubocop:disable Metrics/AbcSize
127+
def handle_standard_error(error)
128+
puts ""
129+
puts Rainbow("❌ UNEXPECTED ERROR").red.bold
130+
puts Rainbow("=" * 80).red
131+
puts Rainbow("🚨 An unexpected error occurred during pack generation:").red
132+
puts ""
133+
puts Rainbow("📋 ERROR DETAILS:").yellow
134+
puts Rainbow(" Type: #{error.class.name}").white
135+
puts Rainbow(" Message: #{error.message}").white
136+
puts Rainbow(" Backtrace:").white
137+
error.backtrace.first(10).each { |line| puts Rainbow(" #{line}").white }
138+
puts Rainbow(" ... (run with --trace for full backtrace)").white
139+
puts ""
140+
puts Rainbow("🔧 DEBUGGING STEPS:").blue.bold
141+
puts Rainbow(" 1. Run: rake react_on_rails:generate_packs --trace").white
142+
puts Rainbow(" 2. Check Rails logs: tail -f log/development.log").white
143+
puts Rainbow(" 3. Verify all dependencies are installed: bundle install && npm install").white
144+
puts Rainbow(" 4. Clear cache: rm -rf tmp/cache").white
28145
puts ""
29-
puts Rainbow("✨ Pack generation completed in #{((end_time - start_time) * 1000).round(1)}ms").green
146+
puts Rainbow("📞 GET HELP:").magenta.bold
147+
puts Rainbow(" • Create an issue: https://github.com/shakacode/react_on_rails/issues").cyan
148+
puts Rainbow(" • Community discussions: https://github.com/shakacode/react_on_rails/discussions").cyan
149+
puts Rainbow(" • Professional support: https://www.shakacode.com/react-on-rails-pro").cyan
150+
puts Rainbow("=" * 80).red
30151
end
152+
# rubocop:enable Metrics/AbcSize
31153
end
154+
# rubocop:enable Metrics/BlockLength

0 commit comments

Comments
 (0)