rails-template icon indicating copy to clipboard operation
rails-template copied to clipboard

Should we install Stimulus JS by default?

Open eoinkelly opened this issue 2 years ago • 0 comments

https://stimulus.hotwired.dev/

It could also be a separate optional variant.

I think I'm currently in favour of it being there by default. My reasoning is below:

The case for including Stimulus in this template

  • I think Stimulus provides sensible structure for JS (vs each team inventing their own conventions for how JS interacts with the DOM). It encodes sensible patterns for connecting JS and the DOM. These patterns have been around for years but many devs aren't aware of them, particularly if they came up in React apps.
  • Even the simplest of Rails apps require at least some JS so I think having the framework installed and an example controller would help teams default into something successful.
  • We already install Turbo and Stimulus is Turbo aware out of the box - vanilla JS (or even jQuery) requires you attach listeners to the turbo load event rather than the normal domContentLoaded event. Also, most Turbo docs online will assume Stimulus.
  • It is quite small (source: https://bundlephobia.com/package/[email protected])
    BUNDLE SIZE 
    33.8kB MINIFIED
    8.4 kB MINIFIED + GZIPPED
    

eoinkelly avatar Aug 20 '22 00:08 eoinkelly