Module: React::ServerRendering

Defined in:
lib/react/server_rendering.rb,
lib/react/server_rendering/bundle_renderer.rb,
lib/react/server_rendering/exec_js_renderer.rb,
lib/react/server_rendering/manifest_container.rb,
lib/react/server_rendering/environment_container.rb,
lib/react/server_rendering/yaml_manifest_container.rb,
lib/react/server_rendering/webpacker_manifest_container.rb

Defined Under Namespace

Classes: BundleRenderer, EnvironmentContainer, ExecJSRenderer, ManifestContainer, PrerenderError, WebpackerManifestContainer, YamlManifestContainer

Class Method Summary collapse

Class Method Details

.render(component_name, props, prerender_options) ⇒ String

Check a renderer out of the pool and use it to render the component.

Parameters:

  • component_name (String)

    Component identifier, looked up by UJS

  • props (String, Hash)

    Props for this component

  • prerender_options (Hash)

    Renderer-specific options

Returns:

  • (String)

    Prerendered HTML from ‘component_name`



25
26
27
28
29
# File 'lib/react/server_rendering.rb', line 25

def self.render(component_name, props, prerender_options)
  @@pool.with do |renderer|
    renderer.render(component_name, props, prerender_options)
  end
end

.reset_poolvoid

This method returns an undefined value.

Discard the old ConnectionPool & create a new one. This will clear all state such as loaded code, JS VM state, or options.



15
16
17
18
# File 'lib/react/server_rendering.rb', line 15

def self.reset_pool
  options = { size: pool_size, timeout: pool_timeout }
  @@pool = ConnectionPool.new(options) { self.renderer.new(self.renderer_options) }
end

.with_rendererObject

Yield a renderer for an arbitrary block



32
33
34
# File 'lib/react/server_rendering.rb', line 32

def self.with_renderer
  @@pool.with { |renderer| yield(renderer) }
end