isomorfeus-preact 22.9.0.rc2 → 22.9.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/isomorfeus/preact/config.rb +0 -1
- data/lib/isomorfeus/preact/ssr.rb +11 -8
- data/lib/isomorfeus/preact/version.rb +1 -1
- data/lib/isomorfeus/preact/view_helper.rb +14 -22
- data/lib/isomorfeus/top_level.rb +3 -4
- data/lib/isomorfeus-preact.rb +0 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d21e147a89cb2cf3634e110df0fe606184d6b87d4069bdd1c20a6b8242cf11d7
|
4
|
+
data.tar.gz: e6bc52cb3de1d9058c5a7c260c103f1d09552fefa8508424cf04d4a9721a2227
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcfd20cd641399287821454d0d09c600ed51a660dd0efc949a5d585166c3c9a29794a4fb7e88271fb03d48aabb33109144e7c6912526b7bf49f302e5aa6b63a6
|
7
|
+
data.tar.gz: a4f55aae16d757584903b3114b77092b8509d759887596681c5935e178f2d1fa2bda97c1ecb8b719adde179bc3a3bebf27916381dce51e85f4b26a0837a10ce1
|
@@ -1,11 +1,6 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
class PreactSSR
|
3
|
-
def
|
4
|
-
rendered_tree = new(component_name, props, session_id, location, locale).render
|
5
|
-
[rendered_tree, Isomorfeus.store.get_state, NanoCSS.instance.renderer[:raw]]
|
6
|
-
end
|
7
|
-
|
8
|
-
def initialize(component_name, props, session_id, location, locale = nil)
|
3
|
+
def initialize(component_name, props, session_id, location, locale)
|
9
4
|
@session_id = session_id
|
10
5
|
@component_name = component_name
|
11
6
|
@props = props
|
@@ -13,12 +8,14 @@ module Isomorfeus
|
|
13
8
|
@locale = locale
|
14
9
|
end
|
15
10
|
|
16
|
-
def render
|
11
|
+
def render(skip_ssr)
|
17
12
|
Isomorfeus.browser_location = Browser::Location.new(@location)
|
18
13
|
Isomorfeus.current_locale = @locale
|
19
14
|
NanoCSS.instance = NanoCSS.new(given_renderer: NanoCSS.global_instance.renderer.deep_dup)
|
20
15
|
Isomorfeus.init_store
|
21
16
|
Isomorfeus.store.clear!
|
17
|
+
Isomorfeus.store.dispatch(type: 'I18N_MERGE', data: { locale: @locale, domain: Isomorfeus.i18n_domain })
|
18
|
+
return '' if skip_ssr
|
22
19
|
c = Isomorfeus.current_user
|
23
20
|
if c.respond_to?(:reload)
|
24
21
|
Thread.current[:isomorfeus_user] = LocalSystem.new
|
@@ -28,7 +25,13 @@ module Isomorfeus
|
|
28
25
|
Thread.current[:isomorfeus_user] = c
|
29
26
|
end
|
30
27
|
end
|
31
|
-
|
28
|
+
render_component_to_string(@component_name, @props)
|
29
|
+
end
|
30
|
+
|
31
|
+
def render_component_to_string(component_name, props)
|
32
|
+
component = component_name.is_a?(String) ? self.class.const_get(component_name) : component_name
|
33
|
+
::Preact._vnode_id = 0
|
34
|
+
::Preact.render_to_string(::Preact.create_element(component, props))
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -4,46 +4,38 @@ module Preact
|
|
4
4
|
base.include Isomorfeus::AssetManager::ViewHelper
|
5
5
|
end
|
6
6
|
|
7
|
-
def cached_mount_component(component_name, props = {}, skip_ssr: false,
|
7
|
+
def cached_mount_component(component_name, props = {}, skip_ssr: false, refresh: false)
|
8
8
|
key = "#{Isomorfeus.current_user}#{component_name}#{props}"
|
9
9
|
if !Isomorfeus.development? && !refresh
|
10
10
|
render_result, @_ssr_styles, status = component_cache.fetch(key)
|
11
11
|
Isomorfeus.ssr_response_status = status
|
12
12
|
return render_result if render_result
|
13
13
|
end
|
14
|
-
render_result = mount_component(component_name, props, asset_key, skip_ssr: skip_ssr
|
14
|
+
render_result = mount_component(component_name, props, asset_key, skip_ssr: skip_ssr)
|
15
15
|
status = ssr_response_status
|
16
16
|
component_cache.store(key, render_result, ssr_styles, status) if status >= 200 && status < 300
|
17
17
|
render_result
|
18
18
|
end
|
19
19
|
|
20
|
-
def mount_component(component_name, props = {}, skip_ssr: false
|
20
|
+
def mount_component(component_name, props = {}, skip_ssr: false)
|
21
21
|
ssr_start_time = Time.now if Isomorfeus.development?
|
22
22
|
@ssr_styles = nil
|
23
|
+
locale = props.delete(:locale)
|
23
24
|
render_result = "<div data-iso-env=\"#{Isomorfeus.env}\" data-iso-root=\"#{component_name}\" data-iso-props='#{Oj.dump(props, mode: :strict)}'"
|
24
|
-
|
25
|
-
|
26
|
-
location = "#{props[:location_scheme] || 'http:'}//#{location_host}#{props[:location]}"
|
25
|
+
location_host = props[:location_host] ? props[:location_host] : 'localhost'
|
26
|
+
location = "#{props[:location_scheme] || 'http:'}//#{location_host}#{props[:location]}"
|
27
27
|
|
28
|
-
|
28
|
+
rendered_tree, application_state, @_ssr_styles = Isomorfeus::TopLevel.mount_component(component_name, props, Thread.current[:isomorfeus_session_id], location, locale, skip_ssr)
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
render_result << " data-iso-nloc='#{props[:locale]}'>"
|
35
|
-
render_result << (rendered_tree ? rendered_tree : "SSR didn't work")
|
36
|
-
else
|
37
|
-
if Isomorfeus.respond_to?(:current_user) && Isomorfeus.current_user && !Isomorfeus.current_user.anonymous?
|
38
|
-
render_result << " data-iso-usids=#{Oj.dump(Isomorfeus.current_user.sid.to_s, mode: :strict)}"
|
39
|
-
end
|
40
|
-
render_result << " data-iso-nloc='#{props[:locale]}'>"
|
30
|
+
render_result << " data-iso-hydrated='true'" unless skip_ssr
|
31
|
+
if Isomorfeus.respond_to?(:current_user) && Isomorfeus.current_user && !Isomorfeus.current_user.anonymous?
|
32
|
+
render_result << " data-iso-usids=#{Oj.dump(Isomorfeus.current_user.sid.to_s, mode: :strict)}"
|
41
33
|
end
|
34
|
+
render_result << '>'
|
35
|
+
render_result << (rendered_tree ? rendered_tree : "SSR didn't work")
|
42
36
|
render_result << '</div>'
|
43
|
-
|
44
|
-
|
45
|
-
puts "Preact::ViewHelper Server Side Rendering took ~#{((Time.now - ssr_start_time)*1000).to_i}ms" if Isomorfeus.development?
|
46
|
-
end
|
37
|
+
render_result = "<script type='application/javascript'>\nServerSideRenderingStateJSON = #{Oj.dump(application_state, mode: :strict)}\n</script>\n" << render_result
|
38
|
+
puts "Preact::ViewHelper Server Side Rendering took ~#{((Time.now - ssr_start_time)*1000).to_i}ms" if Isomorfeus.development?
|
47
39
|
render_result
|
48
40
|
end
|
49
41
|
|
data/lib/isomorfeus/top_level.rb
CHANGED
@@ -117,10 +117,9 @@ module Isomorfeus
|
|
117
117
|
Isomorfeus.top_component = top
|
118
118
|
end
|
119
119
|
else
|
120
|
-
def
|
121
|
-
|
122
|
-
|
123
|
-
::Preact.render_to_string(::Preact.create_element(component, props))
|
120
|
+
def mount_component(component, props, session_id, location, locale, skip_ssr = false)
|
121
|
+
rendered_tree = Isomorfeus::PreactSSR.new(component, props, session_id, location, locale).render(skip_ssr)
|
122
|
+
[rendered_tree, Isomorfeus.store.get_state, NanoCSS.instance.renderer[:raw]]
|
124
123
|
end
|
125
124
|
end
|
126
125
|
end
|
data/lib/isomorfeus-preact.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isomorfeus-preact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 22.9.0.
|
4
|
+
version: 22.9.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
@@ -58,28 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 22.9.0.
|
61
|
+
version: 22.9.0.rc3
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 22.9.0.
|
68
|
+
version: 22.9.0.rc3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: isomorfeus-redux
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 22.9.0.
|
75
|
+
version: 22.9.0.rc3
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 22.9.0.
|
82
|
+
version: 22.9.0.rc3
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: isomorfeus-puppetmaster
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|