isomorfeus-react 16.9.4 → 16.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/isomorfeus/config.rb +1 -0
- data/lib/isomorfeus/react_view_helper.rb +33 -23
- data/lib/react/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bb389b00cc336750921d6f9cbed09d122e248b5502c1133720fb3be193d1fe1
|
4
|
+
data.tar.gz: d189a0b592d10ac2e4817e674930f6e5e01174dd4d9f7b37796126ce4015660d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a504977c3f5ab42da8519b925b672b5b1129ac1d806a466a35f3162f124f25729498cc381c5d3a0272aa3bca0ff65892bce38d7efc9921e49733391658a2141
|
7
|
+
data.tar.gz: ba2e69d7f98e2c6f706dd0bb40f96fbbe34f2c08aa48a6e03fda0c95be9afdfc45f9ff8cb38349b57dfb89592efa4c40433dfb8bf6443754e765a3c24469a225
|
data/lib/isomorfeus/config.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
module ReactViewHelper
|
3
3
|
def mount_component(component_name, props = {}, asset = 'application_ssr.js')
|
4
|
+
@ssr_response_status = nil
|
4
5
|
thread_id_asset = "#{Thread.current.object_id}#{asset}"
|
5
6
|
render_result = "<div data-iso-env=\"#{Isomorfeus.env}\" data-iso-root=\"#{component_name}\" data-iso-props='#{Oj.dump(props, mode: :strict)}'"
|
6
7
|
if Isomorfeus.server_side_rendering
|
@@ -13,9 +14,12 @@ module Isomorfeus
|
|
13
14
|
end
|
14
15
|
|
15
16
|
# build javascript for rendering first pass
|
16
|
-
javascript =
|
17
|
-
|
18
|
-
|
17
|
+
javascript = <<~JAVASCRIPT
|
18
|
+
global.FirstPassFinished = false;
|
19
|
+
global.Opal.Isomorfeus['$force_init!']();
|
20
|
+
global.Opal.Isomorfeus['$ssr_response_status='](200);
|
21
|
+
global.Opal.Isomorfeus.TopLevel['$ssr_route_path=']('#{props[:location]}');
|
22
|
+
JAVASCRIPT
|
19
23
|
|
20
24
|
# if location_host and scheme are given and if Transport is loaded, connect and then render, otherwise do not render
|
21
25
|
ws_scheme = props[:location_scheme] == 'https:' ? 'wss:' : 'ws:'
|
@@ -32,32 +36,34 @@ module Isomorfeus
|
|
32
36
|
global.FirstPassFinished = 'transport';
|
33
37
|
} catch (e) { global.FirstPassFinished = 'transport'; }
|
34
38
|
}, $$1.$$s = this, $$1.$$arity = 0, $$1))
|
35
|
-
} else { global.FirstPassFinished = true };
|
39
|
+
} else { return global.FirstPassFinished = true; };
|
36
40
|
JAVASCRIPT
|
37
41
|
|
38
42
|
# execute first render pass
|
39
|
-
Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
|
43
|
+
first_pass_skipped = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
|
40
44
|
|
41
45
|
# wait for first pass to finish
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
while !first_pass_finished
|
46
|
-
break if (Time.now - start_time) > 10
|
47
|
-
sleep 0.01
|
48
|
-
first_pass_finished = Isomorfeus.ssr_contexts[thread_id_asset].exec('return global.FirstPassFinished')
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# wait for transport requests to finish
|
53
|
-
if first_pass_finished == 'transport'
|
54
|
-
transport_busy = Isomorfeus.ssr_contexts[thread_id_asset].exec('return global.Opal.Isomorfeus.Transport["$busy?"]()')
|
55
|
-
if transport_busy
|
46
|
+
unless first_pass_skipped
|
47
|
+
first_pass_finished = Isomorfeus.ssr_contexts[thread_id_asset].exec('return global.FirstPassFinished')
|
48
|
+
unless first_pass_finished
|
56
49
|
start_time = Time.now
|
57
|
-
while
|
50
|
+
while !first_pass_finished
|
58
51
|
break if (Time.now - start_time) > 10
|
59
52
|
sleep 0.01
|
60
|
-
|
53
|
+
first_pass_finished = Isomorfeus.ssr_contexts[thread_id_asset].exec('return global.FirstPassFinished')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# wait for transport requests to finish
|
58
|
+
if first_pass_finished == 'transport'
|
59
|
+
transport_busy = Isomorfeus.ssr_contexts[thread_id_asset].exec('return global.Opal.Isomorfeus.Transport["$busy?"]()')
|
60
|
+
if transport_busy
|
61
|
+
start_time = Time.now
|
62
|
+
while transport_busy
|
63
|
+
break if (Time.now - start_time) > 10
|
64
|
+
sleep 0.01
|
65
|
+
transport_busy = Isomorfeus.ssr_contexts[thread_id_asset].exec('return global.Opal.Isomorfeus.Transport["$busy?"]()')
|
66
|
+
end
|
61
67
|
end
|
62
68
|
end
|
63
69
|
end
|
@@ -67,11 +73,11 @@ module Isomorfeus
|
|
67
73
|
var rendered_tree = global.Opal.Isomorfeus.TopLevel.$render_component_to_string('#{component_name}', #{Oj.dump(props, mode: :strict)})
|
68
74
|
var application_state = global.Opal.Isomorfeus.store.native.getState();
|
69
75
|
if (typeof global.Opal.Isomorfeus.Transport !== 'undefined') { global.Opal.Isomorfeus.Transport.$disconnect(); }
|
70
|
-
return [rendered_tree, application_state];
|
76
|
+
return [rendered_tree, application_state, global.Opal.Isomorfeus['$ssr_response_status']()];
|
71
77
|
JAVASCRIPT
|
72
78
|
|
73
79
|
# execute second render pass
|
74
|
-
rendered_tree, application_state = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
|
80
|
+
rendered_tree, application_state, @ssr_response_status = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
|
75
81
|
|
76
82
|
# build result
|
77
83
|
render_result << " data-iso-state='#{Oj.dump(application_state, mode: :strict)}'>"
|
@@ -82,5 +88,9 @@ module Isomorfeus
|
|
82
88
|
render_result << '</div>'
|
83
89
|
render_result
|
84
90
|
end
|
91
|
+
|
92
|
+
def ssr_response_status
|
93
|
+
@ssr_response_status || 200
|
94
|
+
end
|
85
95
|
end
|
86
96
|
end
|
data/lib/react/version.rb
CHANGED