Hotwiring Rails Newsletter - November 2021
01 Nov 2021This 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.
Thoughts or feedback on how I can make this newsletter more valuable? Have something you’d like to include in next month’s edition? Send me an email, or find me on Twitter.
Table of contents
- Articles and guides
- New and interesting Rails-land PRs
- Recent pieces from my blog
- The best thing I read recently
Articles and guides
Frontend bundler braindump by Konnor Rogers
This deep dive into the world of frontend bundling is a dense, delightful trip down into the weeds. With Rails 7 dropping Webpacker as the default for new apps and the introduction of importmap-rails, cssbundling-rails, and jsbundling-rails, understanding more about bundling will help Rails devs make sense of all of the new options.
Using Hotwire with Rails for a SPA like experience by Mike Wilson
A neat implementation of list item navigation without a full page turn. Built with Turbo and Stimulus, making great use of a few Turbo events to animate loading states and highlight the active list item. A great read for folks new to the full Hotwire stack
Hotwire: Server-rendered live previews by Sean Doyle
Sean’s work is always thoughtful and thorough, and this article is no different. In it, you’ll build a live preview component with Rails, Stimulus, and Turbo that previews the user’s content as they type. As a nice bonus, the implementation gracefully degrades for users without JavaScript enabled.
Hotwire with StimulusReflex by Julian Rubisch
Hotwire isn’t the only option out there for building modern Rails applications — CableReady and StimulusReflex are excellent tools to have in your bag. In this slide deck, Julian (a StimulusReflex core team member) talks through how he thinks about combining the Hotwire stack with StimulusReflex. Essential reading if you’re trying to figure out how all of the pieces fit together in the real world.
View the slides on speakerdeck.com
Hotwire: best practices for Stimulus by Pete Hawkins
This article shows off a few simple, reusable Stimulus controllers that can be dropped in to any Stimulus-enabled application. Autosubmitting, empty states, toggling and more. Simple, generic components that make a great introduction to some useful Stimulus patterns and libraries like stimulus-use for folks getting started with Stimulus.
Hotwire Turbo: Increment likes count without any page refreshes by Yaroslav Shmarov
A short and sweet piece from Yaroslav demonstrating the implementation of a Turbo Stream powered like button. This is a simple introduction for Turbo Stream beginners who are already comfortable with Rails and want to explore what Turbo can add to toolkit.
New and interesting PRs
Rails 7
- Stop failing CSRF token generation when session is disabled — This PR, merged into Rails main last month, fixes a bug introduced in Rails 7 alpha 1 that breaks rendering forms and buttons outside of the normal controller context. Until this bug fix, rendering something like a delete button from a Turbo Stream or CableReady broadcast was broken in Rails 7, as first described here.
- ActionCable client ensures subscription command is confirmed — This PR, merged into Rails main last week, should eliminate nagging ActionCable connection failures that were all to common, especially when using Turbo Stream broadcasts.
- Add support for generated columns in PostgreSQL — This PR, merged into Rails main in September, adds support for generated columns in Postgres to ActiveRecord, eliminating the need to drop down to writing raw SQL when you need a generated column. Especially useful for things like pg_search migrations.
CableReady
- Receive morph updates from model/PORO callbacks — This PR, merged into CableReady’s 5.0 prerelease, adds the ability to broadcast updates from a model to many subscribers, customizing the content for each user. Perfect for SaaS apps with complex permission levels that need to reference current_user in broadcasted content, inspired by Bullet Train’s Sprinkles library.
cssbundling-rails
- Add Tailwind styled scaffold templates — This PR, merged into cssbundling-rails in September, does what it says on the tin. Adding some basic, Tailwind-powered scaffolds (with designs sanctioned by the Tailwind team) makes it even easier to get nice looking prototypes together with Rails and Tailwind
Recent pieces from my blog
- Turbo Frames on Rails — Turbo’s documentation, especially for the turbo-rails gem, is… lacking. While the official docs may eventually catch up, I spent time compiling what I’ve learned over the last year of building with Turbo to write up some simple how-tos, tricks, and gotchas as a companion to my Turbo Streams on Rails article from August.
- Sorting, searching, and filtering with Hotwire — This is a two part series for folks newer to Turbo that walks through building an (almost) instant search, filter, and sort experience with Turbo Frames and a little bit of Stimulus.
The best thing I read recently
The Single-Page-App Morality Play by Baldur Bjarnason
Baldur uses the never ending debate about SPAs as a jumping off point for a broader discussion of the pitfalls that almost every team of web developers deals with as they try (and usually fail) to deliver great software. There’s no code here, and no easy answers, but if you’re reading this newsletter you’ll probably enjoy reading and thinking about Baldur’s piece.
Until we accept that most of the industry is poorly managed and try to figure out how to solve that problem, sites and web apps won’t get better, just shinier and with more bounce.
Read the entire article at baldurbjarnason.com
That’s all for this month, thanks for reading and for your support! If you enjoyed this newsletter, I would appreciate you sharing it with your friends.