Sha256: c13db8df052167696622c4b05439c2f1482a87a54dc161eb12bc1f30a319ed5e

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

module Isomorfeus
  class PreactSSR
    def initialize(component_name, props, session_id, location, locale)
      @session_id = session_id
      @component_name = component_name
      @props = props
      @location = location
      @locale = locale
    end

    def render(skip_ssr)
      Isomorfeus.browser_location = Browser::Location.new(@location)
      Isomorfeus.current_locale = @locale
      NanoCSS.instance = NanoCSS.new(given_renderer: NanoCSS.global_instance.renderer.deep_dup)
      Isomorfeus.init_store
      Isomorfeus.store.clear!
      Isomorfeus.store.dispatch(type: 'I18N_MERGE', data: { locale: @locale, domain: Isomorfeus.i18n_domain })
      return '' if skip_ssr
      c = Isomorfeus.current_user
      if c.respond_to?(:reload)
        Thread.current[:isomorfeus_user] = LocalSystem.new
        begin
          c.reload
        ensure
          Thread.current[:isomorfeus_user] = c
        end
      end
      render_component_to_string(@component_name, @props)
    end

    def render_component_to_string(component_name, props)
      component = component_name.is_a?(String) ? self.class.const_get(component_name) : component_name
      ::Preact._vnode_id = 0
      ::Preact.render_to_string(::Preact.create_element(component, props))
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
isomorfeus-preact-22.9.0.rc8 lib/isomorfeus/preact/ssr.rb
isomorfeus-preact-22.9.0.rc7 lib/isomorfeus/preact/ssr.rb
isomorfeus-preact-22.9.0.rc6 lib/isomorfeus/preact/ssr.rb
isomorfeus-preact-22.9.0.rc5 lib/isomorfeus/preact/ssr.rb
isomorfeus-preact-22.9.0.rc4 lib/isomorfeus/preact/ssr.rb
isomorfeus-preact-22.9.0.rc3 lib/isomorfeus/preact/ssr.rb