rails-hotwire
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 | drive- |
| 2 | Turbo Frames | CRITICAL | frame- |
| 3 | Turbo Streams | HIGH | stream- |
| 4 | Broadcasting & Real-Time | HIGH | bcast- |
| 5 | Morphing & Page Refresh | HIGH | morph- |
| 6 | Performance Optimization | MEDIUM-HIGH | perf- |
| 7 | Stimulus Patterns | MEDIUM-HIGH | stim- |
| 8 | Architecture Decisions | MEDIUM | arch- |
| 9 | Testing Hotwire | MEDIUM | test- |
Quick Reference
1. Navigation & Drive (CRITICAL)
drive-prefetch-links- Enable link prefetching for instant navigationdrive-form-submissions- Use Turbo Drive for form submissionsdrive-visit-actions- Control history with visit actionsdrive-cache-control- Configure Turbo cache for preview pagesdrive-selective-disable- Disable Turbo Drive on incompatible pagesdrive-progress-bar- Customize the Turbo progress bardrive-confirm-dialog- Use data-turbo-confirm for destructive actionsdrive-error-recovery- Handle Turbo navigation and fetch errors gracefully
2. Turbo Frames (CRITICAL)
frame-lazy-loading- Defer frame loading until viewport entryframe-scope-navigation- Scope navigation within framesframe-src-navigation- Use src for dynamic frame contentframe-break-out- Handle frame breakout for redirectsframe-promote-visits- Promote frame navigation to page visitsframe-dom-id- Use dom_id for frame identificationframe-empty-state- Provide meaningful frame loading states
3. Turbo Streams (HIGH)
stream-progressive-enhance- Always provide HTML fallback for streamsstream-action-selection- Choose the right stream action for DOM mutationsstream-multi-target- Use targets for multi-element updatesstream-http-delivery- Deliver streams via HTTP for form responsesstream-websocket-source- Connect WebSocket sources in the bodystream-custom-actions- Register custom stream actions for complex DOM updates
4. Broadcasting & Real-Time (HIGH)
bcast-model-broadcasts- Use broadcasts_refreshes for simple model updatesbcast-debounce-n1- Debounce broadcasts to prevent N+1 broadcast stormsbcast-scope-streams- Scope broadcast streams to accounts or usersbcast-refresh-over-replace- Prefer broadcast refresh over granular stream updatesbcast-avoid-view-logic-in-models- Keep broadcasting logic out of modelsbcast-signed-stream-names- Use signed stream names for securitybcast-reconnect-handling- Handle WebSocket disconnection and reconnection
5. Morphing & Page Refresh (HIGH)
morph-enable-page-refresh- Enable morphing for page refreshesmorph-permanent-elements- Mark stateful elements as permanentmorph-scroll-preservation- Preserve scroll position during morphingmorph-stimulus-reconnect- Handle Stimulus controller reconnection after morphmorph-frame-refresh- Use refresh='morph' on frames for additive contentmorph-vs-streams- Choose morphing over complex stream orchestration
6. Performance Optimization (MEDIUM-HIGH)
perf-optimistic-ui- Implement optimistic UI updates before server confirmationperf-batch-streams- Batch multiple stream updates into single responsesperf-frame-caching- Cache Turbo Frame responses with fragment cachingperf-prefetch-strategic- Disable prefetch on expensive endpointsperf-memory-leak-prevention- Clean up subscriptions and event listeners
7. Stimulus Patterns (MEDIUM-HIGH)
stim-outlets-communication- Use outlets for cross-controller communicationstim-values-reactive-state- Use Values API for reactive controller statestim-action-descriptors- Use declarative action descriptors over addEventListenerstim-small-reusable-controllers- Keep Stimulus controllers small and reusable
8. Architecture Decisions (MEDIUM)
arch-progressive-enhancement- Follow the progressive enhancement hierarchyarch-frame-vs-stream-decision- Use frames for scoped navigation, streams for multi-target updatesarch-importmap-management- Pin JavaScript dependencies with import mapsarch-avoid-client-state- Keep state on the server, not the clientarch-stimulus-boundaries- Use Stimulus only for client-side behavior
9. Testing Hotwire (MEDIUM)
test-system-test-async- Wait for Turbo updates in system teststest-stream-assertions- Use Turbo Stream test helpers in integration teststest-broadcast-assertions- Assert broadcasts with Turbo test helperstest-frame-navigation- Test frame navigation with scoped assertionstest-websocket-timing- Handle WebSocket connection timing in system tests
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 |
More from pproenca/dot-skills
zod
Zod schema validation best practices for type safety, parsing, and error handling. This skill should be used when defining z.object schemas, using z.string validations, safeParse, or z.infer. This skill does NOT cover React Hook Form integration patterns (use react-hook-form skill) or OpenAPI client generation (use orval skill).
2.0Kclean-architecture
Clean Architecture principles and best practices from Robert C. Martin's book. This skill should be used when designing software systems, reviewing code structure, or refactoring applications to achieve better separation of concerns. Triggers on tasks involving layers, boundaries, dependency direction, entities, use cases, or system architecture.
1.4Kemilkowal-animations
Emil Kowalski's animation best practices for web interfaces. Use when writing, reviewing, or implementing animations in React, CSS, or Framer Motion. Triggers on tasks involving transitions, easing, gestures, toasts, drawers, or motion.
918vitest
Vitest testing framework patterns for test setup, async testing, mocking with vi.*, snapshots, and test performance (formerly test-vitest). This skill should be used when writing or debugging Vitest tests. This skill does NOT cover TDD methodology (use test-tdd skill), API mocking with MSW (use test-msw skill), or Jest-specific APIs.
907typescript
This skill should be used when the user asks to "optimize TypeScript performance", "speed up tsc compilation", "configure tsconfig.json", "fix type errors", "improve async patterns", or encounters TS errors (TS2322, TS2339, "is not assignable to"). Also triggers on .ts, .tsx, .d.ts file work involving type definitions, module organization, or memory management. Does NOT cover TypeScript basics, framework-specific patterns, or testing.
821nuqs
nuqs (type-safe URL query state) best practices for Next.js applications. This skill should be used when writing, reviewing, or refactoring code that uses nuqs for URL state management. Triggers on tasks involving useQueryState, useQueryStates, search params, URL state, query parameters, nuqs parsers, or Next.js routing with state.
735