From superpowers-rails
Defines conventions for Stimulus controllers in Rails: Turbo-first, thin controllers with DOM-only logic, proper cleanup, and preferred naming.
How this skill is triggered — by the user, by Claude, or both
Slash command
/superpowers-rails:rails-stimulus-conventionsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
The best Stimulus controller is one you don't write because Turbo handles it. When JS is needed, keep it thin — DOM interaction only.
The best Stimulus controller is one you don't write because Turbo handles it. When JS is needed, keep it thin — DOM interaction only.
disconnect() must undo what connect() createsimport { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["output"]
static values = { url: String }
connect() { /* setup */ }
disconnect() { /* cleanup timers, observers, listeners */ }
handleClick(event) {
event.preventDefault()
Turbo.visit(this.urlValue) // Prefer Turbo over fetch
}
}
static targets and static values at topconnect() for setup, disconnect() for cleanuphandle* (e.g., handleClick)# prefix// WRONG - manual fetch
async load() {
const html = await fetch(this.urlValue).then(r => r.text())
this.outputTarget.innerHTML = html
}
// RIGHT - let Turbo handle it
handleClick() { Turbo.visit(this.urlValue) }
Or use lazy Turbo frames: <%= turbo_frame_tag "content", src: path, loading: :lazy %>
| Do | Don't |
|---|---|
| DOM manipulation only | Business logic in JS |
| Turbo for updates | Fetch + manual DOM |
static targets/values | Query selectors |
disconnect() cleanup | Memory leaks |
handle* naming | Inconsistent names |
disconnect()Remember: Turbo first. Stimulus only for what HTML can't express.
npx claudepluginhub fryga-io/superpowers-rails --plugin superpowers-railsCreates and refactors Stimulus controllers using Hotwire conventions, design patterns, targets/values, action handling, and JavaScript best practices for interactive UIs.
Applies Better Stimulus best practices for writing maintainable, reusable StimulusJS controllers following SOLID principles. Covers configurable controllers, Values API, declarative events, and focused architecture.
Applies opinionated StimulusJS best practices for writing, reviewing, and refactoring Stimulus controllers. Covers architecture, mixins, state management with Values API, and integration with Hotwire/Turbo.