isomorfeus-preact 10.6.42 → 10.6.46
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 +1 -15
- data/lib/isomorfeus/preact_view_helper.rb +18 -18
- data/lib/isomorfeus/ssr.rb +23 -10
- data/lib/isomorfeus/top_level_ssr.rb +16 -1
- data/lib/preact/version.rb +1 -1
- data/lib/preact.rb +1 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6aa16242ab93d05f360dd9c8b3455dd2e4b4084835116cd8973356edde20d4c
|
4
|
+
data.tar.gz: b230de356c9524d886f9cbfed54edc39c5531d7531b205301358c19acb800809
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0c8247ff444a7f045eb80e6a6d575f957869f87b559df2dba16520ebfe92e2a46d15aee505e9dd908fd4ce061139ff8285a9a9cef7afb6cb75f43d2fd728f50
|
7
|
+
data.tar.gz: acd073c0cb7c199228efa51ed17c1b11612f20670a4cea63b2c382bce7bf1dfef37d43180332de482907b6778fb15cf2d347a5f4a5aa15cdb94e90b02d913635
|
@@ -17,10 +17,7 @@ module Isomorfeus
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def force_init!
|
20
|
-
|
21
|
-
Isomorfeus.initial_state_fetched = true
|
22
|
-
Redux::Store.preloaded_state = Isomorfeus.store.get_state
|
23
|
-
end
|
20
|
+
@initialized = true
|
24
21
|
Isomorfeus.force_init_store!
|
25
22
|
execute_init_classes
|
26
23
|
end
|
@@ -38,17 +35,6 @@ module Isomorfeus
|
|
38
35
|
self.send("#{key}=", value)
|
39
36
|
end
|
40
37
|
|
41
|
-
# only used for SSR
|
42
|
-
def cached_component_classes
|
43
|
-
@cached_component_classes ||= {}
|
44
|
-
end
|
45
|
-
|
46
|
-
# only used for SSR
|
47
|
-
def cached_component_class(class_name)
|
48
|
-
return cached_component_classes[class_name] if cached_component_classes.key?(class_name)
|
49
|
-
cached_component_classes[class_name] = "::#{class_name}".constantize
|
50
|
-
end
|
51
|
-
|
52
38
|
def execute_init_classes
|
53
39
|
client_init_class_names.each do |constant|
|
54
40
|
constant.constantize.send(:init)
|
@@ -27,7 +27,12 @@ module Isomorfeus
|
|
27
27
|
begin
|
28
28
|
init_speednode_context(asset_key, thread_id_asset)
|
29
29
|
rescue Exception => e
|
30
|
-
|
30
|
+
if e.message.include?('@hash[:js][:js][:raw]') # asset bundling did not yet finish
|
31
|
+
sleep 2
|
32
|
+
return mount_component(component_name, props, asset_key, skip_ssr: skip_ssr, use_ssr: use_ssr, max_passes: max_passes)
|
33
|
+
else
|
34
|
+
Isomorfeus.raise_error(message: "Server Side Rendering: Failed creating context for #{asset_key}. Error: #{e.message}", stack: e.backtrace)
|
35
|
+
end
|
31
36
|
end
|
32
37
|
else
|
33
38
|
unless Isomorfeus.ssr_contexts.key?(thread_id_asset)
|
@@ -37,8 +42,7 @@ module Isomorfeus
|
|
37
42
|
|
38
43
|
ctx = Isomorfeus.ssr_contexts[thread_id_asset]
|
39
44
|
pass = 0
|
40
|
-
# if location_host and scheme are given and if Transport is loaded, connect and then render
|
41
|
-
# otherwise do not render because only one pass is required
|
45
|
+
# if location_host and scheme are given and if Transport is loaded, connect and then render
|
42
46
|
ws_scheme = props[:location_scheme] == 'https:' ? 'wss:' : 'ws:'
|
43
47
|
location_host = props[:location_host] ? props[:location_host] : 'localhost'
|
44
48
|
api_ws_path = Isomorfeus.respond_to?(:api_websocket_path) ? Isomorfeus.api_websocket_path : ''
|
@@ -54,7 +58,7 @@ module Isomorfeus
|
|
54
58
|
# execute first render pass
|
55
59
|
begin
|
56
60
|
pass += 1
|
57
|
-
has_transport,
|
61
|
+
has_transport, need_further_pass, exception = ctx.exec(javascript)
|
58
62
|
Isomorfeus.raise_error(message: "Server Side Rendering: #{exception['message']}", stack: exception['stack']) if exception
|
59
63
|
rescue Exception => e
|
60
64
|
Isomorfeus.raise_error(error: e)
|
@@ -91,14 +95,10 @@ module Isomorfeus
|
|
91
95
|
Isomorfeus.raise_error(message: "Server Side Rendering: #{exception['message']}", stack: exception['stack']) if exception
|
92
96
|
else
|
93
97
|
start_time = Time.now
|
94
|
-
script_key = if has_transport
|
98
|
+
script_key = if has_transport
|
95
99
|
:still_busy
|
96
|
-
elsif has_transport
|
97
|
-
:transport_busy
|
98
|
-
elsif has_store
|
99
|
-
:store_busy
|
100
100
|
else
|
101
|
-
|
101
|
+
:store_busy
|
102
102
|
end
|
103
103
|
while need_further_pass
|
104
104
|
# execute further render passes
|
@@ -110,11 +110,11 @@ module Isomorfeus
|
|
110
110
|
Isomorfeus.raise_error(message: "Server Side Rendering: #{exception['message']}", stack: exception['stack']) if exception
|
111
111
|
if need_further_pass && script_key
|
112
112
|
break if (Time.now - start_time) > 5
|
113
|
-
|
114
|
-
while
|
115
|
-
break if (Time.now - start_time) >
|
116
|
-
sleep 0.
|
117
|
-
|
113
|
+
still_busy = ctx.eval_script(key: script_key)
|
114
|
+
while still_busy
|
115
|
+
break if (Time.now - start_time) > 5
|
116
|
+
sleep 0.005
|
117
|
+
still_busy = ctx.eval_script(key: script_key)
|
118
118
|
end
|
119
119
|
break if pass >= max_passes
|
120
120
|
else
|
@@ -179,10 +179,10 @@ module Isomorfeus
|
|
179
179
|
ctx.exec(ssr_mod)
|
180
180
|
ctx.add_script(key: :first_pass_check, source: '[global.FirstPassFinished, global.NeedFurtherPass, global.Exception ? { message: global.Exception.message, stack: global.Exception.stack } : false ]')
|
181
181
|
ctx.add_script(key: :first_pass_result, source: 'Opal.Isomorfeus.SSR.first_pass_result()')
|
182
|
-
ctx.add_script(key: :still_busy, source: '
|
183
|
-
ctx.add_script(key: :store_busy, source: '
|
182
|
+
ctx.add_script(key: :still_busy, source: 'Opal.Isomorfeus.SSR.still_busy()')
|
183
|
+
ctx.add_script(key: :store_busy, source: 'Opal.Isomorfeus.SSR.store_busy()')
|
184
184
|
ctx.add_script(key: :transport_busy, source: 'global.Opal.Isomorfeus.Transport["$busy?"]()')
|
185
|
-
ctx.add_script(key: :transport_disconnect, source: 'global.Opal.Isomorfeus.
|
185
|
+
ctx.add_script(key: :transport_disconnect, source: 'global.Opal.Isomorfeus.SSR.$disconnect_transport()')
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
data/lib/isomorfeus/ssr.rb
CHANGED
@@ -11,7 +11,6 @@ module Isomorfeus
|
|
11
11
|
global.Exception = false;
|
12
12
|
global.IsomorfeusSessionId = session_id;
|
13
13
|
global.HasTransport = (typeof global.Opal.Isomorfeus.Transport !== 'undefined') && (api_ws_path !== '');
|
14
|
-
global.HasStore = typeof global.Opal.Isomorfeus.store !== 'undefined';
|
15
14
|
global.Opal.Isomorfeus['$env='](env);
|
16
15
|
if (typeof global.Opal.Isomorfeus["$current_locale="] === 'function') { global.Opal.Isomorfeus["$current_locale="](locale); }
|
17
16
|
global.Opal.Isomorfeus['$force_init!']();
|
@@ -22,8 +21,7 @@ module Isomorfeus
|
|
22
21
|
global.Opal.send(global.Opal.Isomorfeus.Transport.$promise_connect(global.IsomorfeusSessionId), 'then', [], ($$1 = function(){
|
23
22
|
try {
|
24
23
|
global.RenderedTree = global.Opal.Isomorfeus.TopLevel.$render_component_to_string(component_name, props);
|
25
|
-
|
26
|
-
global.NeedFurtherPass = (nfp == nil) ? false : nfp;
|
24
|
+
global.NeedFurtherPass = self.still_busy();
|
27
25
|
global.FirstPassFinished = true;
|
28
26
|
} catch (e) {
|
29
27
|
global.Exception = e;
|
@@ -33,16 +31,13 @@ module Isomorfeus
|
|
33
31
|
} else {
|
34
32
|
try {
|
35
33
|
global.RenderedTree = global.Opal.Isomorfeus.TopLevel.$render_component_to_string(component_name, props);
|
36
|
-
|
37
|
-
let nfp = global.Opal.Isomorfeus.store['$recently_dispatched?']();
|
38
|
-
global.NeedFurtherPass = (nfp == nil) ? false : nfp;
|
39
|
-
}
|
34
|
+
global.NeedFurtherPass = self.store_busy();
|
40
35
|
} catch (e) {
|
41
36
|
global.Exception = e;
|
42
37
|
global.NeedFurtherPass = false;
|
43
38
|
}
|
44
39
|
};
|
45
|
-
return [global.HasTransport, global.
|
40
|
+
return [global.HasTransport, global.NeedFurtherPass, global.Exception ? { message: global.Exception.message, stack: global.Exception.stack } : false];
|
46
41
|
}
|
47
42
|
|
48
43
|
self.first_pass_result = function() {
|
@@ -66,10 +61,28 @@ module Isomorfeus
|
|
66
61
|
}
|
67
62
|
let application_state = global.Opal.Isomorfeus.store.native.getState();
|
68
63
|
if (typeof global.NanoCSSInstance !== 'undefined') { ssr_styles = global.NanoCSSInstance.raw }
|
69
|
-
|
70
|
-
global.NeedFurtherPass = (nfp == nil) ? false : nfp;
|
64
|
+
global.NeedFurtherPass = ((global.HasTransport && global.Opal.Isomorfeus.Transport["$busy?"]()) || self.store_busy());
|
71
65
|
return [rendered_tree, application_state, ssr_styles, global.Opal.Isomorfeus['$ssr_response_status'](), global.NeedFurtherPass, global.Exception ? { message: global.Exception.message, stack: global.Exception.stack } : false];
|
72
66
|
}
|
67
|
+
|
68
|
+
self.still_busy = function(){
|
69
|
+
if (global.Opal.Isomorfeus.Transport["$busy?"]()) { return true; }
|
70
|
+
return self.store_busy();
|
71
|
+
}
|
72
|
+
|
73
|
+
self.store_busy = function() {
|
74
|
+
let nfp = global.Opal.Isomorfeus.store["$recently_dispatched?"]();
|
75
|
+
return (nfp == global.Opal.nil) ? false : nfp;
|
76
|
+
}
|
73
77
|
}
|
78
|
+
|
79
|
+
def self.disconnect_transport
|
80
|
+
Isomorfeus::Transport::RequestAgent.agents.each do |agent_id, agent|
|
81
|
+
agent.promise.reject() unless agent.promise.realized?
|
82
|
+
Isomorfeus::Transport::RequestAgent.del!(agent_id)
|
83
|
+
end
|
84
|
+
Isomorfeus::Transport.instance_variable_set(:@requests_in_progress, { requests: {}, agent_ids: {} })
|
85
|
+
Isomorfeus::Transport.disconnect
|
86
|
+
end
|
74
87
|
end
|
75
88
|
end
|
@@ -1,3 +1,9 @@
|
|
1
|
+
module Preact
|
2
|
+
def self.render_to_string(native_preact_element)
|
3
|
+
`Opal.global.Preact.renderToString(native_preact_element)`
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
1
7
|
module Isomorfeus
|
2
8
|
class TopLevel
|
3
9
|
class << self
|
@@ -15,9 +21,18 @@ module Isomorfeus
|
|
15
21
|
component = component_name;
|
16
22
|
}
|
17
23
|
}
|
18
|
-
component =
|
24
|
+
component = cached_component_class(component_name) unless component
|
19
25
|
Preact.render_to_string(Preact.create_element(component, `Opal.Hash.$new(props)`))
|
20
26
|
end
|
27
|
+
|
28
|
+
def cached_component_classes
|
29
|
+
@cached_component_classes ||= {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def cached_component_class(class_name)
|
33
|
+
return cached_component_classes[class_name] if cached_component_classes.key?(class_name)
|
34
|
+
cached_component_classes[class_name] = "::#{class_name}".constantize
|
35
|
+
end
|
21
36
|
end
|
22
37
|
end
|
23
38
|
end
|
data/lib/preact/version.rb
CHANGED
data/lib/preact.rb
CHANGED
@@ -294,11 +294,7 @@ module Preact
|
|
294
294
|
end
|
295
295
|
end
|
296
296
|
|
297
|
-
|
298
|
-
def self.render_to_string(native_preact_element)
|
299
|
-
`Opal.global.Preact.renderToString(native_preact_element)`
|
300
|
-
end
|
301
|
-
end
|
297
|
+
# render_to_string is in top_level_ssr.rb
|
302
298
|
|
303
299
|
def self.unmount_component_at_node(element_or_query)
|
304
300
|
if `(typeof element_or_query === 'string')` || (`(typeof element_or_query.$class === 'function')` && element_or_query.class == String)
|
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: 10.6.
|
4
|
+
version: 10.6.46
|
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-02-
|
11
|
+
date: 2022-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|