Hotwiring Rails Newsletter - April 202204 Apr 2022
This newsletter went out via email to the Hotwiring Rails subscriber list, but I know that not everyone wants another email cluttering up their inbox. For those folks, I’ll always publish the full content of the newletter here too, so you can get all the content with none of the emails. If you’d like to get the next edition of this (monthly) newletter in your inbox, you can subscribe here.
Table of contents
Articles and guides
Distributed Systems In Rails series by Nate Hopkins
This three part series is a super valuable and practical guide to thinking about and structuring distributed systems in Rails. Part one of the series is theoretical, parts two and three offer practical approaches to configuring Sidekiq and database connections properly in production.
The Problem That ViewComponent Solves For Me by Jason Swett
I’ve spent time exploring ViewComponent before, but I’ve always struggled to articulate exactly when I should reach for a component — my brain usually just defaults to helpers and then one day I wake up to a mess of helpers.
In this piece, Jason shares his thought process on why he reaches for ViewComponent in a way that helped me reason more clearly about my own code. No code examples in this one, just thoughts.
Hotwire Handbook Part 1 by Phil Reynolds
This article is a series of small, well-explained features implemented with Turbo Streams.
While the official documentation lags behind, these types of practical, code-heavy demos are the best way for new folks to get started.
Import Maps Under The Hood In Rails 7 by Paweł Dąbrowski
Like many of the new front-end tools released with Rails 7, importmap-rails is not very well documented. This article from Paweł is a thorough look at what import maps are, how they work, and how to use them in your Rails application.
Import maps are not right for every use case, but if you want to explore, this is a great starting starting point.
Dynamically Re-use and Lazy-load Pages Using Hotwire
This article describes an interesting technique from the Avo team to re-use views across the application, with a healthy dose of Turbo Frames in the mix. The use case here is a bit niche, but the technique is neat.
New and interesting PRs and releases
The first Ruby 3.2 preview is out and the headline feature is WASM support. Smart and cool folks will undoubtedly find fun ways to use it, once they’ve had time to explore.
In Turbo-land, a proposal to add a new Stream actions for adding and removing classes from elements has been open since late February — the PR addresses a big limitation of Turbo Streams. Given the philosophy of the project, I will be surprised if this proposal is accepted, but if it is it will be a nice upgrade.
More likely to be accepted is a PR adding support for preloading content with Turbo, improving on limitations of the native
rel=prefetch behavior which can be tricky to use for dynamic content.
Finally, an important Turbo bug fix PR was opened, and hopefully will be merged soon. The bug fixed by this PR can be a blocker for migrating cleanly to Turbo, and the double
turbo:load event firing can cause all sorts of hard to diagnose problems.
My recent writing
Toggling view layouts with Kredis, Turbo Frames, and Rails is a quick look at using the very fun Kredis gem to implement a common UX element.
User notifications with Rails, Noticed, and Hotwire offers a quick introduction to Noticed, and demonstrates using Noticed and Turbo Streams to build real-time in-app notifications with minimal effort. Stay tuned for another article demonstrating the same approach with CableReady soon.