2025 Rails frontend solution: Phlex or ViewComponents?
I'm just wondering what everyone's opinions are on the two. I've always leaned into ViewComponents, but it seems like Phlex is on the come up. What has everyone's experience been with the two as of late?
Side note, I'm a big fan of inertiajs (and wish it was something more considered by the Rails team), however, I am trying to stay closer to Rails and Ruby rather than React, Vue, Svelte etc.
I think Phlex or View Component is mostly personal preference. Phlex will be all Ruby and View Component can be a mix of Ruby classes, ERB, and sidecar Stimulus controllers contained in the same folder. Either way you go they're pretty similar.
I implemented ViewComponents in mortimer.pro first but got pretty frustrated with alle the files needed for setting up a component. With Phlex it's one class and you're away. Only issue I have with Phlex is the "buffer" but if you keep your component in the class and don't let it "stray into ERB" all is well :)
I’ve tried both and honestly it comes down to preference — ViewComponents feels more mature and battle-tested, while Phlex is super clean and fast to work with if you’re comfortable writing more Ruby. I’d say if your team values convention and stability, stick with ViewComponents, but if you’re experimenting or starting fresh, Phlex is worth a serious look.
Interesting comparison! I've used ViewComponents extensively and appreciate their organization. Phlex seems promising for performance, but its ecosystem is newer. Has anyone benchmarked them side-by-side? For simpler components, VC might still be faster to implement. Reminds me, I need to get back to optimizing my website... maybe after a quick Moto X3M run! Staying in the Rails ecosystem is smart, InertiaJS is cool, but keep it simple sometimes.