You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose we deprecate the variants feature and remove it entirely in v4.0 of the ViewComponent framework.
Rationale
The ViewComponent project has supported Action Pack variants since at least v1.16, which allow you to specify multiple templates per component. The component chooses which template to use on render based on the current request variant. Variants were designed to support rendering different markup for mobile vs desktop, etc.
Unfortunately, variants have proven difficult to maintain. In ViewComponent, they work by defining multiple #call_* methods on the component class. Let's look at one of the issues I ran into recently that was exacerbated by variants. Components can inherit from other components, and if the child supports a particular variant but the parent does not (or vice versa), calling super to render the parent can lead to NoMethodErrors. It would be simpler to implement parent rendering if the component only had a single #call method.
A few more issues:
Variants introduce complexity in our test suite. We have tests to make sure Slim and HAML work with variants, for example.
Variants add complexity to the compiler, which is already one of the more complicated classes in the framework.
In my opinion, variants are a complex feature to support that bring very little value. For one thing, it is possible to replicate the existing behavior using a simple if statement in a component's template. But an even more important consideration should be that the same markup should work for multiple screen sizes. These days, modern CSS is more than capable of adding and hiding elements at specific breakpoints.
Thoughts?
The text was updated successfully, but these errors were encountered:
@camertron if you re-file in the VC repo, please also add rails label and get it onto the Primer teams backlog if you want us to discuss actioning on it. Otherwise, I don't think it'll be looked at 😄
@lesliecdubs for sure! I actually turned it into a discussion because I want to get community feedback before deciding to revert it or leave it in. If the community thinks we should deprecate it, I'll file an issue and get it on our board 👍
Proposal
I propose we deprecate the variants feature and remove it entirely in v4.0 of the ViewComponent framework.
Rationale
The ViewComponent project has supported Action Pack variants since at least v1.16, which allow you to specify multiple templates per component. The component chooses which template to use on render based on the current request variant. Variants were designed to support rendering different markup for mobile vs desktop, etc.
Unfortunately, variants have proven difficult to maintain. In ViewComponent, they work by defining multiple
#call_*
methods on the component class. Let's look at one of the issues I ran into recently that was exacerbated by variants. Components can inherit from other components, and if the child supports a particular variant but the parent does not (or vice versa), callingsuper
to render the parent can lead toNoMethodError
s. It would be simpler to implement parent rendering if the component only had a single#call
method.A few more issues:
In my opinion, variants are a complex feature to support that bring very little value. For one thing, it is possible to replicate the existing behavior using a simple
if
statement in a component's template. But an even more important consideration should be that the same markup should work for multiple screen sizes. These days, modern CSS is more than capable of adding and hiding elements at specific breakpoints.Thoughts?
The text was updated successfully, but these errors were encountered: