-
Notifications
You must be signed in to change notification settings - Fork 487
Description
Feature request
Provide an interface for rendering view components outside the context of a request-response cycle (e.g without depending on a controller or view context).
Motivation
Rails 7 ships with Hotwire by default. Turbo Streams are a component of Hotwire that (among other things) allow applications to broadcast HTML "over the wire" based on model changes.
Like Rails, Turbo Streams lean heavily on partials - although you can now broadcast HTML from the model. Since ViewComponents replace partials in lots of scenarios, I think it would be beneficial for the library to integrate seamlessly with Turbo Streams in the same way partials do.
Currently there are few ways to integrate ViewComponents with Turbo Streams, but I think it would be nice to offer an "approved" approach.
- We can use
#render_in(view_context)to broadcast HTML from a controller. - If a component implements a
#callmethod we can invoke it to return HTML and broadcast from a model (or any other class). - We can render the component inside a view partial and broadcast from a model (or any other class).