-
-
Couldn't load subscription status.
- Fork 638
Description
🐛 Bug Report
React on Rails Version: 16.0.1.rc.2
Previous Working Version: 14.2.1
Environment: Test environment with Shakapacker
Summary
React on Rails 16.0.1.rc.2 introduced a regression where server bundle path resolution fails in test environments, causing the gem to look in /public/webpack/test/ instead of the correct Shakapacker output directory /public/packs/.
Root Cause
React on Rails 14.2.1 had robust error handling that would fallback to the Shakapacker output path when bundle lookup failed. This fallback mechanism was removed in v16.0.1.rc.2, breaking applications that rely on it.
In v14.2.1: When manifest lookup failed, React on Rails would gracefully fallback to the correct Shakapacker directory.
In v16.0.1.rc.2: When manifest lookup fails, React on Rails defaults to DEFAULT_GENERATED_ASSETS_DIR which points to /public/webpack/test/ instead of /public/packs/.
Error Symptoms
Errno::ENOENT: No such file or directory @ rb_sysopen - /path/to/app/public/webpack/test/server-bundle.js
The server bundle exists at /public/packs/server-bundle.js but React on Rails is looking in the wrong directory.
Current Workaround
Add this configuration to config/initializers/react_on_rails.rb:
# React on Rails 16 compatibility: Workaround for removed error handling
#
# BREAKING CHANGE in v16: React on Rails 14.2.1 had robust error handling that would
# fallback to the Shakapacker output path when bundle lookup failed. This was removed
# in v16.0.1.rc.2, causing it to look in the wrong directory during tests.
#
# This configuration tells React on Rails where to find bundles in test environment.
# Without this, it defaults to public/webpack/test/ instead of public/packs/
if Rails.env.test?
config.generated_assets_dir = File.join(Rails.root, "public", "packs")
endExpected Behavior
React on Rails should either:
- Restore the fallback mechanism from v14.2.1 that gracefully handled manifest lookup failures
- Improve manifest resolution to correctly find bundles in the Shakapacker output directory
- Document this as a breaking change with clear migration instructions
Reproduction
- Upgrade from React on Rails 14.2.1 to 16.0.1.rc.2
- Run tests that use server-side rendering
- Observe the
Errno::ENOENTerror for server bundle lookup
Environment
- Rails: Various versions (tested with Rails 7+)
- Shakapacker: 8.0.0+
- Bundle output:
/public/packs/(standard Shakapacker configuration) - Failing lookup path:
/public/webpack/test/(React on Rails default)
Impact
This regression breaks existing applications upgrading to React on Rails 16, requiring manual configuration to work around the issue. The fallback mechanism was a valuable feature that should be restored.
Suggested Fix
Restore the error handling and fallback path resolution that existed in v14.2.1, or improve the manifest resolution to correctly handle Shakapacker bundle paths without requiring manual configuration.
Note: This issue was discovered during upgrade of the react-webpack-rails-tutorial from React on Rails 14.2.1 to 16.0.1.rc.2. The workaround is functional but the regression should be addressed for a smooth upgrade experience.