Module: ReactOnRailsPro::Stream
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/react_on_rails_pro/concerns/stream.rb
Instance Method Summary collapse
-
#stream_view_containing_react_components(template:, close_stream_at_end: true, **render_options) ⇒ Object
Streams React components within a specified template to the client.
Instance Method Details
#stream_view_containing_react_components(template:, close_stream_at_end: true, **render_options) ⇒ Object
Note:
The ‘stream_react_component` helper is defined in the react_on_rails gem. For more details, refer to `lib/react_on_rails/helper.rb` in the react_on_rails repository.
Streams React components within a specified template to the client.
components must be added to the view using the ‘stream_react_component` helper.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/react_on_rails_pro/concerns/stream.rb', line 33 def stream_view_containing_react_components(template:, close_stream_at_end: true, **) @rorp_rendering_fibers = [] template_string = render_to_string(template: template, **) # View may contain extra newlines, chunk already contains a newline # Having multiple newlines between chunks causes hydration errors # So we strip extra newlines from the template string and add a single newline response.stream.write(template_string) begin drain_streams_concurrently ensure response.stream.close if close_stream_at_end end end |