Turbo to replace StimulusReflex?

Hey just wanted to get an opinion within the community with regard to advancement of Turbo/Hotwire - do you see this advancement as an entire replacement for the concept behind StimulusReflex or is there still some warranted use for StimulusReflex in conjunction with Turbo/Hotwire?

1 Like

Rails is a big tent and having diversity is important to foster creativity and innovation so I don’t think it’s very useful to think about this in terms of replacement.

It comes down to your personal preference, your team’s preference and the problem at hand. Some apps might do great just with Hotwire, some with StimulusReflex, some with Inertia and some with partial or even full on React. But my personal preference; some will benefit from a combination of some or all of these approaches on a case by case basis.

So rather than replacing one, let’s foster an environment where they all can thrive!

5 Likes

You’re more likely to use them together. There’s actually very little overlap between the two. The only “conflict of interest” you’re going to run into is turbo streams against cable_ready.

Here’s an example in one of my apps:

A user submits a form, it hits a controller, and I update the page using turbo streams. This is all nicely handled by rails and turbo, and it’s all RESTful.

A user moves to a new page, I’ll be leveraging turbo drive to only replace the body, and do all of the requests asynchronously.

A user scrolls down to some data that wasn’t previously visible - I’m going to use turbo frames to defer that partial until it is. I also use turbo frames for encapsulated navigation - Imagine embedding 3 tables on a single page, each frame handles its own pagination. That kind of thing.

If a user clicks a Like button, I’ll use SR to process it, because clicking a like button isn’t RESTful at all, and I’m not going to wrap a button in a form just to try and jam it into a turbo shaped hole.

If I have jobs running in the background, and I want to update the page to reflect some new data, for anyone interested, I’ll probably use cable ready.

I haven’t explored turbo-rails’ automatic broadcasts on model updates yet, but I don’t think that conflicts with anything either.

6 Likes