Consider deprecating variants #1807
-
ProposalI propose we deprecate the variants feature and remove it entirely in v4.0 of the ViewComponent framework. RationaleThe 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 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 Thoughts? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
I agree we should do away with variants, but there's definitely a pocket of folks in the community who are actively using the feature. I think it'd be good to make folks who have raised issues relating to the feature aware of this discussion. |
Beta Was this translation helpful? Give feedback.
-
I'm in favor of removing variant support. I don't feel like the functionality fits well in component based architectures (implicit vs explicit) and it does make the framework code significantly more complex in a lot of cases. In general, I feel like most uses could be replaced with: <% if variant == :mobile %>
<% render Mobile::PageComponent %>
<% else %>
<% render PageComponent %>
<% end %> I like how explicit that is and how easy it is to reason about what will be rendered on the page. I don't use this functionality myself, so I'd love to hear from folks who are using it and what your use-cases are. I'd also like to hear from folks who actively decided not to use variants too. |
Beta Was this translation helpful? Give feedback.
-
I have been using variants mostly as a versioning system when as I example I was building a new design of an app. The views and components would have this (:new) variant. The main advantage of this solution vs a new file name, is that all I18n remains the same and I don’t have to worry about fixing all translation keys paths. If this feature is removed could it be replaced by some kind of versioning system of the component ? |
Beta Was this translation helpful? Give feedback.
-
I've never used the variants feature in Rails, and I can't really find any use case for them in the applications I'm working on (and some are pretty large design systems). Building a We're always trying to keep the markup the same whether it's viewed on mobile or desktop. I feel like the mobile/desktop variants in Rails are kind of a relic of ancient times, when we built separate "low-def" mobile websites. I'm fine with deprecating variants in ViewComponent, especially since keeping it brings quite a lot of overhead when refactoring or building new stuff. I'd love hearing more about specific use cases, though! |
Beta Was this translation helpful? Give feedback.
-
While I tend to agree, I ultimately see variants as a part of Rails we need to support, as doing so keeps us aligned with our overall mission of being |
Beta Was this translation helpful? Give feedback.
While I tend to agree, I ultimately see variants as a part of Rails we need to support, as doing so keeps us aligned with our overall mission of being
a framework for creating reusable, testable & encapsulated view components, built to integrate seamlessly with Ruby on Rails.
That includes supporting parts of Rails we might not all like 😄