by sickcodebruh · 3y ago · 0 comments
But the view layer has not aged well. After years of working with a focus on React and TypeScript, I can't stomach the Rails approach to views. As much as I appreciate the value proposition of Stimulus and truly feel the shortcomings of SPAs deep in my bones, I crave components, type safety, unidirectional data flow, and more options for styling than just classes. React in particular has rich options for UI frameworks that feel truly idiomatic. The last time I tried to start a project with Rails, I moved at a breakneck pace until I got to the view layer, at which point I had to pull the plug.
I'm reaching for Next.js these days because it's the closest I can get. It gives me the opinionated framework I crave plus server rendering and the ability to drop down into client-side rendering when it calls for it. Prisma is a damn good ORM, even if it doesn't have the intuitively ergonomic beauty of ActiveRecord. And of course, TypeScript throughout is a godsend.
But I still miss Rails. I miss the console, Sidekiq, the profound power of ActiveRecord for simple things with the ease of dropping back into SQL when I need it, the polish of FactoryBot and those easy easy easy tests. I miss the breezy and fluid syntax of Ruby. I don't feel limited by TypeScript, I love working with it, but TypeScript lets me lecture, Ruby lets me sing.
Any experience with it? What makes it far from perfect?
I pair Next with Nest (sigh, why only one letter different?) when I need a proper backend but I can get so far with Next that I’m using it less and less now.
If someone reading this has experience with both TS+React and modern Hotwire apps, you’d do the world a service by writing a blog about modern Rails views for the experienced React developer.
Also sprinkle some (rare) Stimulus and Turbo streams/frames.
The one thing you're gonna be missing is typing, Sorbet does not work in views.
Agreed - In my opinion, Rails messaging/soft marketing could be a lot better about how it's great for a data driven backend, whatever the frontend/UI.
I know there's things like API mode and webpacker, but this all seems very secondary and begrudging at times. Maybe I listen too much to what DHH says, but definitely think the Rails view stuff should be what's secondary. It's a turnoff for a lot of devs who would otherwise be quite happy with Rails as a backend.