Skip to content

Generator skips private_output_path configuration when Shakapacker is freshly installed #2289

@ihabadham

Description

@ihabadham

Environment

  1. Ruby version: 3.3.7
  2. Rails version: 8.0.4
  3. Shakapacker version: 9.4.0
  4. React on Rails version: 16.2.0-rc.0

Expected behavior

When running rails generate react_on_rails:install on a fresh Rails app (without Shakapacker pre-installed), the generated config/shakapacker.yml should have private_output_path: ssr-generated uncommented for Shakapacker 9.0+.

Actual behavior

The private_output_path setting remains commented out, causing a runtime warning:

⚠️  Shakapacker 9.0+ detected but private_output_path not configured in shakapacker.yml
   Add to config/shakapacker.yml:
     private_output_path: ssr-generated
   Run: rails react_on_rails:doctor to validate your configuration

Root Cause Analysis

The bug is in base_generator.rb:copy_packer_config (lines 104-120):

def copy_packer_config
  if File.exist?(".shakapacker_just_installed")
    puts "Skipping Shakapacker config copy (already installed by Shakapacker installer)"
    File.delete(".shakapacker_just_installed")
    return  # Completely skips our template!
  end
  # ... our version-conditional template never runs
end

When Shakapacker is freshly installed by ensure_shakapacker_installed, a marker file .shakapacker_just_installed is created. The copy_packer_config method then completely skips copying React on Rails' custom shakapacker.yml.tt template to "avoid conflicts".

However, Shakapacker's default template has private_output_path commented out even in version 9.4.0, while React on Rails' template has conditional logic to uncomment it for Shakapacker 9.0+:

<%% if shakapacker_version_9_or_higher? -%>
  private_output_path: ssr-generated
<%% else -%>
  # private_output_path: ssr-generated  # Uncomment to enable
<%% end -%>

Because we skip our template entirely, this version-conditional logic never executes.

Small, reproducible repo

# Create fresh Rails app without Shakapacker
rails new test_app --minimal --skip-git --skip-bundle --skip-test --skip-javascript

cd test_app

# Add gems
cat >> Gemfile << 'GEMEOF'
gem "shakapacker", "9.4.0"
gem "react_on_rails"
gem "foreman"
GEMEOF

bundle install

# Run generator
bundle exec rails generate react_on_rails:install

# Check result - private_output_path will be commented
grep "private_output_path" config/shakapacker.yml
# Output: # private_output_path: ssr-generated

Suggested Fix

Instead of completely skipping when the marker file exists, patch the file to ensure private_output_path is properly configured:

def copy_packer_config
  if File.exist?(".shakapacker_just_installed")
    puts "Shakapacker was just installed - configuring private_output_path"
    File.delete(".shakapacker_just_installed")
    configure_private_output_path_if_needed  # New method to patch the existing file
    configure_rspack_in_shakapacker if options.rspack?
    return
  end
  # ... existing logic
end

Impact

  • Severity: Low - the warning is cosmetic and SSR bundles work fine without this setting
  • Affected users: Anyone running the generator on a fresh app where Shakapacker wasn't pre-installed

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions