Skip to content

Commit 0fd87c9

Browse files
justin808claude
andcommitted
Fix duplicate rake task execution when Engine rake_tasks called twice
Prevents duplicate task definitions when Rails Engine's rake_tasks block is invoked multiple times during initialization. Each rake file now uses a guard constant to ensure tasks are only defined once. This fixes the issue where react_on_rails:assets:webpack would run the build command twice, causing unnecessary build time and potential issues. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ae8b1b1 commit 0fd87c9

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

lib/tasks/assets.rake

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

3+
# Guard against loading this file multiple times
4+
# This can happen if Engine's rake_tasks block is called more than once during Rails initialization
5+
return if defined?(REACT_ON_RAILS_ASSETS_RAKE_LOADED)
6+
7+
REACT_ON_RAILS_ASSETS_RAKE_LOADED = true
8+
39
# rubocop:disable Metrics/BlockLength
410
namespace :react_on_rails do
511
namespace :assets do

lib/tasks/generate_packs.rake

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

3+
# Guard against loading this file multiple times
4+
# This can happen if Engine's rake_tasks block is called more than once during Rails initialization
5+
return if defined?(REACT_ON_RAILS_GENERATE_PACKS_RAKE_LOADED)
6+
7+
REACT_ON_RAILS_GENERATE_PACKS_RAKE_LOADED = true
8+
39
# rubocop:disable Metrics/BlockLength
410
namespace :react_on_rails do
511
desc <<~DESC

lib/tasks/locale.rake

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

3+
# Guard against loading this file multiple times
4+
# This can happen if Engine's rake_tasks block is called more than once during Rails initialization
5+
return if defined?(REACT_ON_RAILS_LOCALE_RAKE_LOADED)
6+
7+
REACT_ON_RAILS_LOCALE_RAKE_LOADED = true
8+
39
require "react_on_rails/locales/base"
410
require "react_on_rails/locales/to_js"
511
require "react_on_rails/locales/to_json"

0 commit comments

Comments
 (0)