isomorfeus-preact 22.9.0.rc8 → 22.9.0.rc9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/browser/delegate_native.rb +6 -18
- data/lib/isomorfeus/preact/config.rb +1 -2
- data/lib/isomorfeus/preact/ssr.rb +1 -1
- data/lib/isomorfeus/preact/thread_local_component_cache.rb +2 -2
- data/lib/isomorfeus/preact/version.rb +1 -1
- data/lib/isomorfeus/preact/view_helper.rb +19 -21
- data/lib/isomorfeus/top_level.rb +8 -11
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28d9e79cef1f470a18cf3ceb7e24e4b1e87d544bdf3f9ea8e8c466f6e5f135c6
|
4
|
+
data.tar.gz: 0f07f213e0ed7aafb22f7abe64ea41a0b2b1d14dace721dcf01611d19b52f403
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcd883d7865f7b05373510a797cd254fa05fed28f54403c3a6d9c7d9d3ac1e0f51693bca52702b99b0248798339d74dad8a4f178c15611593072a1e5a8eaf6e0
|
7
|
+
data.tar.gz: a937605abfcbe71d93d6d97eb5f6b2783336773dcc7e2a9c3180285d8ccdc6dc011a1d33ba4175d186d6b03a4d47004aa67ad39c57c6f2203bd5e54d63a0bb56
|
@@ -24,29 +24,17 @@ module Browser
|
|
24
24
|
message = message.chop
|
25
25
|
property_name = property_for_message(message)
|
26
26
|
arg = args[0]
|
27
|
-
arg = if `arg && typeof arg.$to_n === 'function'`
|
28
|
-
|
29
|
-
else
|
30
|
-
arg
|
31
|
-
end
|
32
|
-
return `#@native[#{property_name}] = args[0]`
|
27
|
+
arg = arg.to_n if `arg && typeof arg.$to_n === 'function'`
|
28
|
+
return `#@native[#{property_name}] = arg`
|
33
29
|
else
|
34
30
|
property_name = property_for_message(message)
|
35
|
-
|
36
31
|
%x{
|
37
32
|
let value = #@native[#{property_name}];
|
38
33
|
let type = typeof(value);
|
34
|
+
if (type === 'undefined') { return #{super}; }
|
39
35
|
try {
|
40
36
|
if (type === 'function') {
|
41
|
-
#{
|
42
|
-
args.map! do |arg|
|
43
|
-
if `arg && typeof arg.$to_n === 'function'`
|
44
|
-
arg.to_n
|
45
|
-
else
|
46
|
-
arg
|
47
|
-
end
|
48
|
-
end
|
49
|
-
}
|
37
|
+
#{args.map! { |arg| `arg && typeof arg.$to_n === 'function'` ? arg.to_n : arg }}
|
50
38
|
value = value.apply(#@native, args);
|
51
39
|
}
|
52
40
|
if (value instanceof HTMLCollection || value instanceof NodeList) {
|
@@ -69,9 +57,9 @@ module Browser
|
|
69
57
|
end
|
70
58
|
|
71
59
|
def respond_to_missing? message, include_all
|
72
|
-
|
60
|
+
return true if message.end_with? '='
|
73
61
|
property_name = property_for_message(message)
|
74
|
-
return true
|
62
|
+
return true if `#{property_name} in #@native`
|
75
63
|
false
|
76
64
|
end
|
77
65
|
|
@@ -28,8 +28,7 @@ module Isomorfeus
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def force_render
|
31
|
-
|
32
|
-
Preact.unmount_component_at_node(root_element)
|
31
|
+
Preact.unmount_component_at_node(`document.body`)
|
33
32
|
Isomorfeus::TopLevel.do_the_mount!(init: false)
|
34
33
|
nil
|
35
34
|
rescue Exception => e
|
@@ -10,7 +10,7 @@ module Isomorfeus
|
|
10
10
|
|
11
11
|
def render(skip_ssr)
|
12
12
|
Isomorfeus.browser_location = Browser::Location.new(@location)
|
13
|
-
Isomorfeus.current_locale = @locale
|
13
|
+
Isomorfeus.current_locale = @locale if @locale
|
14
14
|
NanoCSS.instance = NanoCSS.new(given_renderer: NanoCSS.global_instance.renderer.deep_dup)
|
15
15
|
Isomorfeus.init_store
|
16
16
|
Isomorfeus.store.clear!
|
@@ -8,8 +8,8 @@ module Isomorfeus
|
|
8
8
|
Thread.current[:local_cache][key]
|
9
9
|
end
|
10
10
|
|
11
|
-
def store(key, rendered_tree,
|
12
|
-
Thread.current[:local_cache][key] = [rendered_tree,
|
11
|
+
def store(key, rendered_tree, styles, data, status)
|
12
|
+
Thread.current[:local_cache][key] = [rendered_tree, styles, data, status]
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -13,36 +13,42 @@ module Preact
|
|
13
13
|
end
|
14
14
|
render_result = mount_component(component_name, props, asset_key, skip_ssr: skip_ssr)
|
15
15
|
status = ssr_response_status
|
16
|
-
component_cache.store(key, render_result, ssr_styles, status) if status >= 200 && status < 300
|
16
|
+
component_cache.store(key, render_result, ssr_styles, ssr_data, status) if status >= 200 && status < 300
|
17
17
|
render_result
|
18
18
|
end
|
19
19
|
|
20
20
|
def mount_component(component_name, props = {}, skip_ssr: false)
|
21
21
|
ssr_start_time = Time.now if Isomorfeus.development?
|
22
|
-
@ssr_styles = nil
|
23
22
|
locale = props.delete(:locale)
|
24
|
-
render_result = "<div data-iso-env=\"#{Isomorfeus.env}\" data-iso-root=\"#{component_name}\" data-iso-props='#{Oj.dump(props, mode: :strict)}'"
|
25
23
|
location_host = props[:location_host] ? props[:location_host] : 'localhost'
|
26
24
|
location = "#{props[:location_scheme] || 'http:'}//#{location_host}#{props[:location]}"
|
27
25
|
|
28
26
|
rendered_tree, application_state, @_ssr_styles = Isomorfeus::TopLevel.mount_component(component_name, props, Thread.current[:isomorfeus_session_id], location, locale, skip_ssr)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
27
|
+
component_name = component_name.to_s unless component_name.is_a?(String)
|
28
|
+
usids = if Isomorfeus.respond_to?(:current_user) && Isomorfeus.current_user && !Isomorfeus.current_user.anonymous?
|
29
|
+
Isomorfeus.current_user.sid.to_s
|
30
|
+
else
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
@_ssr_data = <<~HTML
|
35
|
+
<script type='application/javascript'>
|
36
|
+
ServerSideRenderingStateJSON = #{Oj.dump(application_state, mode: :strict)}
|
37
|
+
ServerSideRenderingProps = #{Oj.dump({ env: Isomorfeus.env, component_name: component_name, props: props, hydrated: !skip_ssr, usids: usids }, mode: :strict)}
|
38
|
+
</script>
|
39
|
+
HTML
|
38
40
|
puts "Preact::ViewHelper Server Side Rendering took ~#{((Time.now - ssr_start_time)*1000).to_i}ms" if Isomorfeus.development?
|
39
|
-
|
41
|
+
rendered_tree ? rendered_tree : "SSR didn't work"
|
40
42
|
end
|
41
43
|
|
42
44
|
def ssr_response_status
|
43
45
|
Isomorfeus.ssr_response_status
|
44
46
|
end
|
45
47
|
|
48
|
+
def ssr_data
|
49
|
+
@_ssr_data
|
50
|
+
end
|
51
|
+
|
46
52
|
def ssr_styles
|
47
53
|
@_ssr_styles || ''
|
48
54
|
end
|
@@ -52,13 +58,5 @@ module Preact
|
|
52
58
|
def component_cache
|
53
59
|
@_component_cache ||= Isomorfeus.component_cache_init_block.call
|
54
60
|
end
|
55
|
-
|
56
|
-
def ssr_mod
|
57
|
-
@_ssr_mod ||= Opal.compile(File.read(File.expand_path(File.join(File.dirname(__FILE__), 'ssr.rb'))), { use_strict: true })
|
58
|
-
end
|
59
|
-
|
60
|
-
def top_level_mod
|
61
|
-
@_top_level_mod ||= Opal.compile(File.read(File.expand_path(File.join(File.dirname(__FILE__), 'top_level_ssr.rb'))), { use_strict: true })
|
62
|
-
end
|
63
61
|
end
|
64
62
|
end
|
data/lib/isomorfeus/top_level.rb
CHANGED
@@ -7,11 +7,10 @@ module Isomorfeus
|
|
7
7
|
if RUBY_ENGINE == 'opal'
|
8
8
|
def do_the_mount!(init: true)
|
9
9
|
NanoCSS.instance = NanoCSS.new({ sh: `document.getElementById('css-server-side')` })
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
Isomorfeus.
|
14
|
-
Isomorfeus.current_user_sid_s = root_element.JS.getAttribute('data-iso-usids')
|
10
|
+
p = `global.ServerSideRenderingProps`
|
11
|
+
component_name = p.JS[:component_name]
|
12
|
+
Isomorfeus.env = p.JS[:env]
|
13
|
+
Isomorfeus.current_user_sid_s = p.JS[:usids]
|
15
14
|
component = nil
|
16
15
|
begin
|
17
16
|
component = component_name.constantize
|
@@ -29,14 +28,12 @@ module Isomorfeus
|
|
29
28
|
end
|
30
29
|
end
|
31
30
|
if component
|
32
|
-
|
33
|
-
props = JSON.parse(props_json)
|
31
|
+
props = Hash.new(p.JS[:props])
|
34
32
|
if init
|
35
|
-
|
36
|
-
Isomorfeus::TopLevel.hydrated = (raw_hydrated && raw_hydrated == "true")
|
33
|
+
Isomorfeus::TopLevel.hydrated = p.JS[:hydrated]
|
37
34
|
%x{
|
38
|
-
if (global.ServerSideRenderingStateJSON) {
|
39
35
|
var state = global.ServerSideRenderingStateJSON;
|
36
|
+
if (state) {
|
40
37
|
var keys = Object.keys(state);
|
41
38
|
for(var i=0; i < keys.length; i++) {
|
42
39
|
if (Object.keys(state[keys[i]]).length > 0) {
|
@@ -49,7 +46,7 @@ module Isomorfeus
|
|
49
46
|
end
|
50
47
|
begin
|
51
48
|
Isomorfeus::TopLevel.first_pass = true
|
52
|
-
result = Isomorfeus::TopLevel.mount_component(component, props,
|
49
|
+
result = Isomorfeus::TopLevel.mount_component(component, props, `document.body`, Isomorfeus::TopLevel.hydrated)
|
53
50
|
Isomorfeus::TopLevel.first_pass = false
|
54
51
|
@tried_another_time = false
|
55
52
|
result
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.rc9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -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.rc9
|
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.rc9
|
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.rc9
|
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.rc9
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: isomorfeus-puppetmaster
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|