I’ve lived through this sort of sea change twice now – first with the abandonment of Prototype.js, and now with Sprockets. In both cases, the cusp time was the very worst.
It’s impossible to overstate how confusing it is for me to try to use code that currently works (oh, let’s just name it: bootstrap.js) in a new module-preferring world where jQuery doesn’t exist as a window object. The quantity and severity of code-smells I contributed in just trying to get a modal to be reusable by multiple controllers was quite astounding. And the amount of really bad advice I encountered in the SO-verse and Blog-land made this very difficult to climb as a learning curve. Gems that I have used to inject bits of magic into the front-end and relied on for years just don’t work any more, and their README is no longer authoritative.
Eventually, this will all work itself out, as gems are updated, and Bootstrap 5 brings us a new, modular JS without a jQuery requirement. Rails is a big tent, and it casts a long shadow, and all the sideshow folks will want to come along in whichever direction the train is heading. (Sorry to mangle the metaphor.)
Right now, because I want to ship something this month, I resorted to injecting external script references to jQuery, the Bootstrap CDN, and my tiny little file of extensions to that code (written in what I like to call Ye Olde jQuerie) – all 55 lines of it, including comments and whitespace – into application.html.erb, and called it a night. This resulted in the removal of hundreds of NPM bundles (yay!) and a halving of the size of my application.js (yes, I know it all went in other files, which all load from CDNs, so I’ve just moved the junk drawer).
It was a humbling defeat for someone who has been writing JavaScript as a side job since 1997, who still is the List Mom for the prototype-scriptaculous mailing list. I’d really like to believe that this is the way forward, but it is not for me, at least not this year.
So much of this tooling is built around the very real needs of front-end developers who don’t have the luxury of a mature framework like Rails, who have to build each thing from scratch. It all feels like so much Astronaut Architecture when you bring it into the context of wanting to handle an Ajax update from a modal form. I use Rails because I don’t build SPAs. I don’t need a whole SPA factory full of custom tools designed around solving a problem that I don’t have.
I can see the appeal of using the same tooling that JS-heavy front-end devs are experienced with, so that Rails devs who manage the deployment of multi-tiered JS-heavy applications can fit right in. In my mind, that smacks of the same false syllogism that gave us “run JS on the server, what could go wrong?” and “one language everywhere – your devs can be twice as versatile”. I would love if this could be optional, for those who need it, and that something more fit to a JavaScript-lite approach was still layered in there somewhere.
My two pfennigs, anyway.
Walter