A pattern for building self-refreshing UI components in Rails using ViewComponent and Hotwire. Instead of managing turbo_streams with partials and scattered dom_ids, components encapsulate their own refresh logic, broadcast channels, and identifiers. This approach improves maintainability by keeping related behavior together and eliminates the need to track magic strings across multiple files. The pattern includes conditional streaming to avoid keeping connections open unnecessarily and demonstrates real-time UI updates for background job progress.
Table of contents
A tangled mess of identifiersView Components to the rescueDo we need to keep the stream open for eternity?ConclusionSort: