Module: ReactOnRailsPro::RSCPayloadRenderer

Extended by:
ActiveSupport::Concern
Included in:
RscPayloadController
Defined in:
lib/react_on_rails_pro/concerns/rsc_payload_renderer.rb

Instance Method Summary collapse

Instance Method Details

#rsc_payloadObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/react_on_rails_pro/concerns/rsc_payload_renderer.rb', line 12

def rsc_payload
  @rsc_payload_component_name = rsc_payload_component_name
  @rsc_payload_component_props = rsc_payload_component_props

  stream_view_containing_react_components(
    template: custom_rsc_payload_template,
    layout: false,
    # Render as text so Rails does not inject HTML view annotation comments
    # into the NDJSON stream. Custom template overrides must resolve to a
    # text or format-neutral template, not `.html.erb`.
    formats: [:text],
    content_type: "application/x-ndjson"
  )
rescue ActionView::MissingTemplate => e
  raise e.exception(
    "[React on Rails Pro] RSC payload templates are now rendered with format :text. " \
    "If you override `custom_rsc_payload_template`, make sure the override resolves to " \
    "a text or format-neutral template (for example `rsc_payload.text.erb`) instead of " \
    "only `.html.erb`. See react_on_rails_pro/docs/updating.md for upgrade notes.\n\n" \
    "Original error: #{e.message}"
  )
end