Skip to content

Fix load order issues for 3rd-party template handlers#2547

Open
camertron wants to merge 2 commits intomainfrom
fix_load_order
Open

Fix load order issues for 3rd-party template handlers#2547
camertron wants to merge 2 commits intomainfrom
fix_load_order

Conversation

@camertron
Copy link
Contributor

What are you trying to accomplish?

This PR is a fix for the bug described by #2448 and #2409. It simply loads ActionView::Base before ViewComponent::Base, which ensures all template handlers are registered correctly before ViewComponent starts compiling templates.

What approach did you choose and why?

As @edolix discovered in #2409 and reproduced in https://github.com/edolix/view-component-bug-replica (thank you!), ActionView::Template.template_handler_extensions does not contain "slim" before some components are loaded. As a result, VC can find no template for the affected components. Even when the slim template handler does eventually get registered with ActionView, VC doesn't notice because it memoizes the result of the template lookup.

As @joelhawksley correctly surmised, the bug was introduced when ViewComponent::Base stopped inheriting from ActionView::Base. The inheritance originally caused ActionView::Base to load before ViewComponent::Base, and, crucially, triggered ActionView load hooks. The load hooks feature is the mechanism Slim (and I would imagine other template engines) use to register themselves. Removing the inheritance causes ActionView::Base to load at a different point during the boot process, and thus delays the template engines from registering their handlers as well.

The fix is really simple: just require action_view/base. There should be no negative side-effects of doing so, since inheriting from ActionView::Base effectively requires action_view/base and thereby reproduces the previous behavior.

@camertron camertron changed the title Fix load order issues for 3rd-party template libraries Fix load order issues for 3rd-party template handlers Feb 6, 2026
@edolix
Copy link

edolix commented Feb 6, 2026

Thank you @camertron!

As I was looking at the VC source code, I imagined it was something "simple but not that obvious" - at least for me without any knowledge of the code base :)

Thank you! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants