Fix load order issues for 3rd-party template handlers#2547
Open
Fix load order issues for 3rd-party template handlers#2547
Conversation
|
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! 🙏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What are you trying to accomplish?
This PR is a fix for the bug described by #2448 and #2409. It simply loads
ActionView::BasebeforeViewComponent::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_extensionsdoes 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::Basestopped inheriting fromActionView::Base. The inheritance originally causedActionView::Baseto load beforeViewComponent::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 causesActionView::Baseto 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 fromActionView::Baseeffectively requiresaction_view/baseand thereby reproduces the previous behavior.