install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/pproenca/dot-skills/rails-hotwire" ~/.claude/skills/comeonoliver-skillshub-rails-hotwire && rm -rf "$T"
manifest:
skills/pproenca/dot-skills/rails-hotwire/SKILL.mdsource content
Community Rails Hotwire Best Practices
Comprehensive guide for building interactive Rails applications with Hotwire (Turbo + Stimulus), maintained by Community. Contains 53 rules across 9 categories, prioritized by impact to guide automated refactoring and code generation. Follows the DHH "One Person Framework" philosophy: the server renders HTML, Turbo makes it feel like an SPA, Stimulus adds the sprinkle of JS where needed.
When to Apply
Reference these guidelines when:
- Configuring Turbo Drive navigation, prefetching, and caching behavior
- Adding Turbo Frames for partial page updates and lazy loading
- Delivering Turbo Streams for surgical DOM mutations
- Broadcasting real-time updates over ActionCable
- Enabling Turbo 8 morphing for page refreshes
- Writing Stimulus controllers for client-side behavior
- Handling errors in Turbo navigation, frames, and WebSocket connections
- Choosing between Drive, Frames, Streams, Morphing, and Stimulus
- Testing Hotwire interactions in system and integration tests
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Navigation & Drive | CRITICAL | |
| 2 | Turbo Frames | CRITICAL | |
| 3 | Turbo Streams | HIGH | |
| 4 | Broadcasting & Real-Time | HIGH | |
| 5 | Morphing & Page Refresh | HIGH | |
| 6 | Performance Optimization | MEDIUM-HIGH | |
| 7 | Stimulus Patterns | MEDIUM-HIGH | |
| 8 | Architecture Decisions | MEDIUM | |
| 9 | Testing Hotwire | MEDIUM | |
Quick Reference
1. Navigation & Drive (CRITICAL)
- Enable link prefetching for instant navigationdrive-prefetch-links
- Use Turbo Drive for form submissionsdrive-form-submissions
- Control history with visit actionsdrive-visit-actions
- Configure Turbo cache for preview pagesdrive-cache-control
- Disable Turbo Drive on incompatible pagesdrive-selective-disable
- Customize the Turbo progress bardrive-progress-bar
- Use data-turbo-confirm for destructive actionsdrive-confirm-dialog
- Handle Turbo navigation and fetch errors gracefullydrive-error-recovery
2. Turbo Frames (CRITICAL)
- Defer frame loading until viewport entryframe-lazy-loading
- Scope navigation within framesframe-scope-navigation
- Use src for dynamic frame contentframe-src-navigation
- Handle frame breakout for redirectsframe-break-out
- Promote frame navigation to page visitsframe-promote-visits
- Use dom_id for frame identificationframe-dom-id
- Provide meaningful frame loading statesframe-empty-state
3. Turbo Streams (HIGH)
- Always provide HTML fallback for streamsstream-progressive-enhance
- Choose the right stream action for DOM mutationsstream-action-selection
- Use targets for multi-element updatesstream-multi-target
- Deliver streams via HTTP for form responsesstream-http-delivery
- Connect WebSocket sources in the bodystream-websocket-source
- Register custom stream actions for complex DOM updatesstream-custom-actions
4. Broadcasting & Real-Time (HIGH)
- Use broadcasts_refreshes for simple model updatesbcast-model-broadcasts
- Debounce broadcasts to prevent N+1 broadcast stormsbcast-debounce-n1
- Scope broadcast streams to accounts or usersbcast-scope-streams
- Prefer broadcast refresh over granular stream updatesbcast-refresh-over-replace
- Keep broadcasting logic out of modelsbcast-avoid-view-logic-in-models
- Use signed stream names for securitybcast-signed-stream-names
- Handle WebSocket disconnection and reconnectionbcast-reconnect-handling
5. Morphing & Page Refresh (HIGH)
- Enable morphing for page refreshesmorph-enable-page-refresh
- Mark stateful elements as permanentmorph-permanent-elements
- Preserve scroll position during morphingmorph-scroll-preservation
- Handle Stimulus controller reconnection after morphmorph-stimulus-reconnect
- Use refresh='morph' on frames for additive contentmorph-frame-refresh
- Choose morphing over complex stream orchestrationmorph-vs-streams
6. Performance Optimization (MEDIUM-HIGH)
- Implement optimistic UI updates before server confirmationperf-optimistic-ui
- Batch multiple stream updates into single responsesperf-batch-streams
- Cache Turbo Frame responses with fragment cachingperf-frame-caching
- Disable prefetch on expensive endpointsperf-prefetch-strategic
- Clean up subscriptions and event listenersperf-memory-leak-prevention
7. Stimulus Patterns (MEDIUM-HIGH)
- Use outlets for cross-controller communicationstim-outlets-communication
- Use Values API for reactive controller statestim-values-reactive-state
- Use declarative action descriptors over addEventListenerstim-action-descriptors
- Keep Stimulus controllers small and reusablestim-small-reusable-controllers
8. Architecture Decisions (MEDIUM)
- Follow the progressive enhancement hierarchyarch-progressive-enhancement
- Use frames for scoped navigation, streams for multi-target updatesarch-frame-vs-stream-decision
- Pin JavaScript dependencies with import mapsarch-importmap-management
- Keep state on the server, not the clientarch-avoid-client-state
- Use Stimulus only for client-side behaviorarch-stimulus-boundaries
9. Testing Hotwire (MEDIUM)
- Wait for Turbo updates in system teststest-system-test-async
- Use Turbo Stream test helpers in integration teststest-stream-assertions
- Assert broadcasts with Turbo test helperstest-broadcast-assertions
- Test frame navigation with scoped assertionstest-frame-navigation
- Handle WebSocket connection timing in system teststest-websocket-timing
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |