Skip to content

Commit 9010bc3

Browse files
committed
Add troubleshooting docs for duplicate rake task bug in versions < 16.2.0
1 parent ad0b47a commit 9010bc3

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

docs/deployment/troubleshooting-build-errors.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This guide covers common webpack build errors encountered when using react_on_ra
88
- [ProvidePlugin Module Resolution Errors](#provideplugin-module-resolution-errors)
99
- [Environment Setup Dependencies](#environment-setup-dependencies)
1010
- [Shakapacker Compatibility Issues](#shakapacker-compatibility-issues)
11+
- [Duplicate Build Execution (Versions < 16.2.0)](#duplicate-build-execution-versions--1620)
1112
- [For Coding Agents](#for-coding-agents)
1213

1314
## Missing Routes File Error (js-routes gem)
@@ -199,6 +200,66 @@ Some operations require a working Rails environment:
199200
2. Update webpack configurations
200201
3. Regenerate configurations with `rails generate react_on_rails:install`
201202

203+
## Duplicate Build Execution (Versions < 16.2.0)
204+
205+
### Symptom
206+
207+
If you're using React on Rails **versions before 16.2.0**, you may notice:
208+
209+
- Asset precompilation takes twice as long as expected
210+
- Webpack build runs twice during `rake assets:precompile`
211+
- Console output shows duplicate webpack compilation messages
212+
- CI builds are slower than necessary
213+
214+
### Root Cause
215+
216+
In versions prior to 16.2.0, a bug in the Rails Engine caused rake task files to be loaded twice:
217+
218+
1. Once via explicit `load` calls in the Engine's `rake_tasks` block
219+
2. Once via Rails Engine's automatic file loading from `lib/tasks/`
220+
221+
This resulted in tasks like `react_on_rails:assets:webpack`, `react_on_rails:generate_packs`, and `react_on_rails:locale` executing twice.
222+
223+
### Solution
224+
225+
**Upgrade to React on Rails 16.2.0 or later:**
226+
227+
```bash
228+
# Update Gemfile
229+
gem 'react_on_rails', '~> 16.2'
230+
231+
# Install
232+
bundle update react_on_rails
233+
```
234+
235+
The issue is fixed in version 16.2.0 ([PR #2052](https://github.com/shakacode/react_on_rails/pull/2052)).
236+
237+
### Workaround for Older Versions
238+
239+
If you cannot upgrade immediately, you can temporarily work around this by creating an initializer:
240+
241+
```ruby
242+
# config/initializers/react_on_rails_fix.rb
243+
Rails.application.config.after_initialize do
244+
# Only apply if using affected versions
245+
next unless ReactOnRails::VERSION < '16.2.0'
246+
247+
# Remove duplicate task actions
248+
%w[
249+
react_on_rails:assets:webpack
250+
react_on_rails:generate_packs
251+
react_on_rails:locale
252+
].each do |task_name|
253+
next unless Rake::Task.task_defined?(task_name)
254+
255+
task = Rake::Task[task_name]
256+
task.actions.uniq! if task.actions.length > 1
257+
end
258+
end
259+
```
260+
261+
**Note:** This workaround is not recommended for production. Upgrade to 16.2.0+ for the proper fix.
262+
202263
## For Coding Agents
203264

204265
### Automated Diagnostics

0 commit comments

Comments
 (0)