Module: UniversalRenderer::Renderable

Extended by:
ActiveSupport::Concern
Defined in:
lib/universal_renderer/renderable.rb

Defined Under Namespace

Modules: Streaming

Instance Method Summary collapse

Instance Method Details

#fetch_ssrHash?

Fetches Server-Side Rendered (SSR) content for the current request. This method makes a blocking call to the SSR service and stores the result in the @ssr instance variable.

The SSR content is fetched based on the request.original_url and the @universal_renderer_props accumulated for the request.

Returns:

  • (Hash, nil)

    The fetched SSR data (typically a hash with keys like :head, :body_html, :body_attrs), or nil if the fetch fails or SSR is not configured.



43
44
45
46
47
48
49
50
# File 'lib/universal_renderer/renderable.rb', line 43

def fetch_ssr
  props = @universal_renderer_props || {}
  @ssr =
    UniversalRenderer::Client::Base.call(
      request.original_url,
      props
    )
end

#renderObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/universal_renderer/renderable.rb', line 56

def render(*, **)
  return super unless self.class.ssr_enabled
  return super unless request.format.html?

  # Allow Warden and other authentication mechanisms to complete first
  # This prevents interference with authentication throws like :warden
  if ssr_streaming?
    success = render_ssr_stream(*, **)
    super unless success
  else
    fetch_ssr
    super
  end
end

#ssr_streaming?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/universal_renderer/renderable.rb', line 52

def ssr_streaming?
  self.class.ssr_streaming_preference
end