Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ After a release, please make sure to run `bundle exec rake update_changelog`. Th

Changes since the last non-beta release.

#### Fixed

- **Duplicate Rake Task Execution**: Fixed rake tasks executing twice during asset precompilation and other rake operations. Rails Engine was loading task files twice: once via explicit `load` calls in the `rake_tasks` block (Railtie layer) and once via automatic file loading from `lib/tasks/` (Engine layer). This caused `react_on_rails:assets:webpack`, `react_on_rails:generate_packs`, and `react_on_rails:locale` tasks to run twice, significantly increasing build times. Removed explicit `load` calls and now rely on Rails Engine's standard auto-loading behavior. [PR 2052](https://github.com/shakacode/react_on_rails/pull/2052) by [justin808](https://github.com/justin808).

### [v16.2.0.beta.8] - 2025-11-16

#### Added
Expand Down
61 changes: 61 additions & 0 deletions docs/deployment/troubleshooting-build-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This guide covers common webpack build errors encountered when using react_on_ra
- [ProvidePlugin Module Resolution Errors](#provideplugin-module-resolution-errors)
- [Environment Setup Dependencies](#environment-setup-dependencies)
- [Shakapacker Compatibility Issues](#shakapacker-compatibility-issues)
- [Duplicate Build Execution (Versions < 16.2.0)](#duplicate-build-execution-versions--1620)
- [For Coding Agents](#for-coding-agents)

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

## Duplicate Build Execution (Versions < 16.2.0)

### Symptom

If you're using React on Rails **versions before 16.2.0**, you may notice:

- Asset precompilation takes twice as long as expected
- Webpack build runs twice during `rake assets:precompile`
- Console output shows duplicate webpack compilation messages
- CI builds are slower than necessary

### Root Cause

In versions prior to 16.2.0, a bug in the Rails Engine caused rake task files to be loaded twice:

1. Once via explicit `load` calls in the Engine's `rake_tasks` block
2. Once via Rails Engine's automatic file loading from `lib/tasks/`

This resulted in tasks like `react_on_rails:assets:webpack`, `react_on_rails:generate_packs`, and `react_on_rails:locale` executing twice.

### Solution

**Upgrade to React on Rails 16.2.0 or later:**

```bash
# Update Gemfile
gem 'react_on_rails', '~> 16.2'

# Install
bundle update react_on_rails
```

The issue is fixed in version 16.2.0 ([PR #2052](https://github.com/shakacode/react_on_rails/pull/2052)).

### Workaround for Older Versions

If you cannot upgrade immediately, you can temporarily work around this by creating an initializer:

```ruby
# config/initializers/react_on_rails_fix.rb
Rails.application.config.after_initialize do
# Only apply if using affected versions
next unless ReactOnRails::VERSION < '16.2.0'

# Remove duplicate task actions
%w[
react_on_rails:assets:webpack
react_on_rails:generate_packs
react_on_rails:locale
].each do |task_name|
next unless Rake::Task.task_defined?(task_name)

task = Rake::Task[task_name]
task.actions.uniq! if task.actions.length > 1
end
end
```

**Note:** This workaround is not recommended for production. Upgrade to 16.2.0+ for the proper fix.

## For Coding Agents

### Automated Diagnostics
Expand Down
7 changes: 2 additions & 5 deletions lib/react_on_rails/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ def self.package_json_missing?
ReactOnRails::ServerRenderingPool.reset_pool
end

rake_tasks do
load File.expand_path("../tasks/generate_packs.rake", __dir__)
load File.expand_path("../tasks/assets.rake", __dir__)
load File.expand_path("../tasks/locale.rake", __dir__)
end
# Rake tasks are automatically loaded from lib/tasks/*.rake by Rails::Engine
# No need to explicitly load them here to avoid duplicate loading
end
end
Loading