HotWire doesn’t feel very Rails-y. It's a step forward from creating SPAs for the tinyest website, but it could have been so much better. It could

Unpoly is what Hotwire should have been

submited by
Style Pass
2024-05-09 21:30:04

HotWire doesn’t feel very Rails-y. It's a step forward from creating SPAs for the tinyest website, but it could have been so much better. It could’ve been like Unpoly.

The problem with Hotwire, is that it's a lot of work. You need WebSockets (for Turbo Streams) as soon as you try to do something slightly complicated. And you’ll need StimulusJS to handle the slightest interactivity.

Let’s take a pretty common use case in most applications. Showing a form in a modal. Here’s what you’d need to do to create that with HotWire (taken from this HotWire tutorial):Include the modal container somewhere in your page by default, so that you can target itCall the server to GET the form template and target the modalCreate StimulusJS controller to add a close/cancel button to your modal (by removing the content from the DOM)Use Turbo Streams to update your original page (the one underneath the modal) without a page refresh when a post is updated or createdCreate another SimulusJS controller that listens for server events and closes the modal when a submission is successful

Here’s what the same thing would look like with Unpoly:<div up-href="/post/new" up-layer="new" up-mode="modal" up-target="#post_content" up-on-accepted="up.reload('#post_list')" > Add post </div>

Leave a Comment