Developer Happiness: StimulusReflex v3.4
Tags: rails, javascript, webdev, ruby
Published: 2020-12-18 16:52:39

---
title: Developer Happiness: StimulusReflex v3.4
published: true
description: Release announcement for StimulusReflex v3.4
tags: rails, javascript, webdev, ruby
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/ubgikpd7ys0fg0hs83ro.jpg
---

It's red letter day: after three months of development and *nine* pre-release candidates, StimulusReflex v3.4 has finally [dropped](https://rubygems.org/gems/stimulus_reflex).

The introduction of [Morphs](https://docs.stimulusreflex.com/morph-modes#introducing-morphs) in September elevated StimulusReflex from a cool proof-of-concept to a promising tool for building reactive UIs.

[![Reflex is faster than a reaction.](https://svbtleusercontent.com/oZaURzYg1pBnK5AvswEzct0xspap_small.jpg)](https://svbtleusercontent.com/oZaURzYg1pBnK5AvswEzct0xspap.jpg)

Open source projects need to think creatively to stand out. **Hiring an actor to record a fake testimonial by a beloved fictional douchebag didn't compute for some.** The [initial tweet](https://twitter.com/theleastbad/status/1308401495185010700) was watched 9,100 times with 111 re-tweets, resulting in 27,000 impressions and 4,200 engagements. The [YouTube version](https://www.youtube.com/watch?v=utxCm3uLhIE) has been viewed 5,800 times to date. This prompted a flurry of high profile articles, most notably Rails legend Obie Fernandez's epic "[React is dead. Long live Reactive Rails. Long live StimulusReflex and ViewComponent](https://medium.com/@obie/react-is-dead-long-live-reactive-rails-long-live-stimulusreflex-and-viewcomponent-cd061e2b0fe2)". StimulusReflex was the featured story in [Ruby Weekly](https://rubyweekly.com/issues/520). Jason Charnes announced that [a course](https://courses.jasoncharnes.com/stimulus-reflex) is in the works. Ruby Hero Ryan Bates asked Digital Ocean to [donate $5,000](https://twitter.com/rbates/status/1331379415008247808) to the project. Membership on our [Discord](https://discord.gg/XveN625) has doubled, and our weekly downloads went from under 5,000 to [over 12,000](https://www.npmjs.com/package/stimulus_reflex).

Perhaps most importantly, **we've crossed the rubicon from being mocked to being seen as a threat**. Given the thousands of hours passionately invested in building and supporting StimulusReflex and CableReady, $600 to 5x our name recognition and establish this stack as a preferable alternative to JS-based SPAs - *pretty much over night* - seems like a solid return on investment.

Knowing that we're influencing the direction of Rails itself is possibly the most gratifying upside of all. As evidenced by DHH gradually walking-back [earlier statements](https://twitter.com/patmisch/status/1252772796633137152) saying the long-promised *NEW MAGIC* is "[unrelated](https://twitter.com/dhh/status/1225612112556281858)" to StimulusReflex, the narrative has progressively evolved from "[similar in intent](https://twitter.com/dhh/status/1275907797431902213)" to "[an alternative to](https://twitter.com/dhh/status/1336959367879516162)" StimulusReflex. We want Rails to kick ass and we're glad to be keeping one of our heroes on his toes. Granted, it's getting harder and harder for him to imply that he "discovered" these ideas in a fevered burst of primordial creative insight.

---

When I think about what "developer happiness" means to me, it comes down to two things:

- a magical sense of "things just work", made possible by ideas like the Principle of Least Surprise, intelligent defaults, methods that you hope will be there *and they are*, and the defenestration of ceremony and boilerplate code
- the anticipation and mitigation of painful things that could otherwise reduce my happiness

# Things Just Work

The recent method chaining capability of CableReady v4.4 combined with the magic `cable_ready` method available inside of Reflex actions is a great example of things working very well. In StimulusReflex v3.3, using CableReady to replace an element for the current user looked like this:

[![chrome_56nIIZv2s0.png](https://svbtleusercontent.com/xhSiN8RxQdKrBX3BPyAnYc0xspap_small.png)](https://svbtleusercontent.com/xhSiN8RxQdKrBX3BPyAnYc0xspap.png)

Here's the same thing in StimulusReflex v3.4. How's that for "conceptual compression"?

[![chrome_VQqKSbP9BP.png](https://svbtleusercontent.com/9HLD6ALUMxH2HHd82Fpexc0xspap_small.png)](https://svbtleusercontent.com/9HLD6ALUMxH2HHd82Fpexc0xspap.png)

As of StimulusReflex v3.4 and CableReady v4.3, every time a DOM event is created, a jQuery event with the same name and details is *also* created - but only if the jQuery library is present and detected in the current application. We welcome the millions of jQuery users with open arms.

There are two new features that are subtle but exciting:

- we've introduced a new [finalize](https://docs.stimulusreflex.com/lifecycle#client-side-reflex-callbacks) life-cycle stage that runs *after* all CableReady operations triggered by Morphs have finished. It's perfect for initiating animations and Turbolinks navigations
- there's now an optional "[tab isolation](https://docs.stimulusreflex.com/reflexes#tab-isolation)" mode, which makes sure that Morphs only impact the DOM of the browser tab that initiated the Reflex

You can also magically [unpack signed Global ID](https://docs.stimulusreflex.com/reflexes#signed-and-unsigned-global-id-accessors)s right into ActiveRecord models. As the Great Dane often says, "look at all of the code I didn't have to write!"

# Mitigation of Pain

It has to be the ultimate cliche in software development that every new release is described as faster, with fewer bugs and far more robust.

v3.4 isn't just faster, with fewer bugs and far more robust... it's also substantially smaller, with the client footprint shrinking to just [11kb](https://bundlephobia.com/result?p=stimulus_reflex@3.4.0-pre9) including CableReady, morphdom and ActionCable.

Stimulus 2 Just Works. You can use v1.1, too. Whatever you like.

Significant client-side refactoring made our vastly improved [logging module](https://docs.stimulusreflex.com/troubleshooting#client-side-logging), tab isolation and the `finalize` stage possible while ensuring that multiple concurrent Reflexes can be in-flight without corruption or side-effects. We're also far more forgiving in scenarios where the element which initiates a Reflex is replaced - a major source of confusion for newcomers in the past.

It's not just the client that has been given white glove treatment, either: v3.4 introduces a brand new [server-side logging](https://docs.stimulusreflex.com/troubleshooting#stimulusreflex-logging) module that is *disturbingly* customizable without being "too much":

[![WindowsTerminal_dQPv6fcNZM.png](https://svbtleusercontent.com/eUaty7cud2fxtXNkCoB1Vj0xspap_small.png)](https://svbtleusercontent.com/eUaty7cud2fxtXNkCoB1Vj0xspap.png)

We've added an initializer, but the defaults are so intelligent, it's very likely that you'll never change them. That said, it's nice to know that if you need your Page Morphs to support [Rack middleware](https://docs.stimulusreflex.com/setup#rack-middleware-support), it's super easy.

Speaking of pain: weird bugs due to mismatched gem + npm package versions are now a thing of the past. StimulusReflex will now yell loudly *and abort* if versions don't match... unless you turn warnings off in the initializer.

*One more thing...* while it's not technically part of the SR/CR stack, I released a Stimulus controller called [radiolabel](https://www.npmjs.com/package/radiolabel) that gives you visual feedback on your CableReady operations as they happen in development. It's an easy way to make debugging your app faster and more explicit.

---

The coolest and most profound [changes](https://docs.stimulusreflex.com/#new-release-v-3-4-developer-happiness-edition) in v3.4 came from community contributors, sometimes making their first PRs. In particular, I'd like to call out the code and support efforts of folks like [Roland Studer](https://github.com/rolandstuder), [Konnor Rogers](https://github.com/paramagicdev), [Piotr Wodz](https://github.com/piotrwodz), [Chris Oliver](https://github.com/excid3) and [Rafe Rosen](https://github.com/existentialmutt).

Meanwhile, [Josh LeBlanc](https://github.com/joshleblanc) and his [View Component Reflex](http://view-component-reflex-expo.grep.sh/) might rightfully be considered our secret weapon(s).

A personal thanks to all of the contributors, including my co-conspirators [Nate Hopkins](https://github.com/hopsoft), [Julian Rubisch](https://github.com/julianrubisch) and [Marco Roth](https://github.com/marcoroth).

[![resistance.jpg](https://svbtleusercontent.com/pfMPiGsvVmN5FxqXd3vtEU0xspap_small.jpg)](https://svbtleusercontent.com/pfMPiGsvVmN5FxqXd3vtEU0xspap.jpg)

NEW MAGIC is a wing of the #resistance, and the #resistance is kicking ass.

Remember: a reflex is faster than a reaction. ❤️