Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider deprecating variants #2152

Closed
camertron opened this issue Jul 21, 2023 · 3 comments
Closed

Consider deprecating variants #2152

camertron opened this issue Jul 21, 2023 · 3 comments
Labels

Comments

@camertron
Copy link
Contributor

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), 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:

  1. Variants introduce complexity in our test suite. We have tests to make sure Slim and HAML work with variants, for example.
  2. 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?

@camertron
Copy link
Contributor Author

Woops! I meant to file this in the ViewComponent repo 🤦

@lesliecdubs
Copy link
Member

@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 😄

@camertron
Copy link
Contributor Author

camertron commented Jul 21, 2023

@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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants