Skip to content

Missing privateOutputPath computed property in JS config (private_output_path feature incomplete on JS side) #890

@ihabadham

Description

@ihabadham

Summary

The private_output_path configuration (added in PR #592 / #604) works correctly on the Ruby side but is missing its computed JS-side property. This causes React on Rails' generated serverWebpackConfig.js to always fall back to a hardcoded path, breaking the sync between shakapacker.yml and webpack output.

Expected behavior

config.privateOutputPath should be available as a computed absolute path on the JS config object, following the same pattern as config.outputPath:

const { config } = require('shakapacker')
console.log(config.outputPath)        // "/app/public/packs" (works)
console.log(config.privateOutputPath)  // "/app/ssr-generated" (expected)

Actual behavior

const { config } = require('shakapacker')
console.log(config.outputPath)         // "/app/public/packs" (works)
console.log(config.privateOutputPath)  // undefined
console.log(config.private_output_path) // "ssr-generated" (raw YAML string, not absolute)

Reproduction

rails new test_app --minimal --skip-git --skip-bundle --skip-test
cd test_app

# Add shakapacker, install, configure private_output_path
echo 'gem "shakapacker", "9.4.0"' >> Gemfile
bundle install
rails shakapacker:install

# Set private_output_path in config/shakapacker.yml under default:
#   private_output_path: ssr-generated

# Check JS config
node -e "
  const config = require('./node_modules/shakapacker/package/config.js');
  console.log('outputPath:', config.outputPath);
  console.log('privateOutputPath:', config.privateOutputPath);
  console.log('private_output_path:', config.private_output_path);
"
# outputPath: /path/to/test_app/public/packs
# privateOutputPath: undefined        <-- BUG
# private_output_path: ssr-generated   <-- raw YAML, not absolute

Root cause

PR #592 added private_output_path to the Ruby-side Shakapacker::Configuration class (returning an absolute path via root_path.join(private_path)), but did not add the corresponding computed property to the JS-side config.ts.

The existing pattern in config.ts:

// Public output: YAML snake_case -> computed camelCase absolute path
config.outputPath = resolve(config.public_root_path, config.public_output_path)

// Private output: missing equivalent
// Should be:
// if (config.private_output_path) {
//   config.privateOutputPath = resolve(config.private_output_path)
// }

Impact

React on Rails' generated serverWebpackConfig.js (from PR shakacode/react_on_rails#2028) uses config.privateOutputPath for the server bundle output path. Since the property is always undefined:

  1. False warning on every build: "Shakapacker 9.0+ detected but private_output_path not configured" fires even when it IS configured
  2. Broken config sync: Changing private_output_path in shakapacker.yml has no effect on webpack output. The template always falls back to a hardcoded path. This defeats the purpose of the feature.

User report: shakacode/react_on_rails#2289 (comment)

Suggested fix

In package/config.ts, after the outputPath computation:

config.outputPath = resolve(config.public_root_path, config.public_output_path)

// Add computed privateOutputPath (matching outputPath pattern)
if (config.private_output_path) {
  config.privateOutputPath = resolve(config.private_output_path)
}

And update the Config interface in package/types.ts:

export interface Config {
  // ... existing properties ...
  privateOutputPath?: string  // Computed absolute path for private output
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions