Fix: Use Rails::Engine for Propshaft compatibility#72
Fix: Use Rails::Engine for Propshaft compatibility#72mickeytgl wants to merge 3 commits intomarcoroth:mainfrom
Conversation
ReActionView's dev-tools assets were not found when using Propshaft (Rails 8's default asset pipeline) because it used Sprockets-specific asset path registration. Changed from Rails::Railtie to Rails::Engine, which automatically registers app/assets directories with both Sprockets and Propshaft.
|
@marcoroth No rush, but small bump |
| # If you don't want to precompile ReActionView's assets (eg. because you're using propshaft), | ||
| # you can do this in an initializer: | ||
| # | ||
| # config.after_initialize do | ||
| # config.assets.precompile -= ReActionView::Railtie::PRECOMPILE_ASSETS | ||
| # end | ||
| # |
There was a problem hiding this comment.
I think we still want to keep this comment, no?
| # config.assets.precompile -= ReActionView::Railtie::PRECOMPILE_ASSETS | ||
| # end | ||
| # | ||
| class Engine < Rails::Engine |
There was a problem hiding this comment.
I'm confused why we need this 🤔
I have been using ReActionView in multiple apps with Propshaft and haven't come across this error. I wonder if it's something else that might be causing this issue. And coincidentally, changing to an Engine makes it go away too.
Co-authored-by: Chris Oliver <excid3@gmail.com>
|
Ok, I've dug deeper into this. It was kind of my fault by doing something weird, but this might still be relevant. To reproduce:
@marcoroth You might not run into this if you've never precompiled assets locally. Without a manifest, Propshaft falls back to its Dynamic resolver which checks the load path at runtime and finds the assets just fine. But because ReActionView registers its assets as a Railtie instead of an Engine and Propshaft only auto-discovers assets from Engines, ReActionView's dev-tools JS files never make it into the precompiled manifest. If that manifest is lying around in development (e.g. from a production precompile), Propshaft uses that and doesn't find the assets. |
ReActionView's dev-tools assets were not found when using Propshaft because it used Sprockets-specific asset path registration.
Changed from Rails::Railtie to Rails::Engine, which automatically registers app/assets directories with both Sprockets and Propshaft.
I did notice the comment suggesting to put
config.assets.precompile -= ReActionView::Railtie::PRECOMPILE_ASSETSin the initializer once I dug in and that works well, but I think it's still worth it since this would fix the root cause and it saves some time for people on propshaft from running into an errorExample