isomorfeus-react 16.9.1 → 16.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a0447c4d5c434a9d6608cfed365e179e11b1dd936a2f511d2745516b2704e3b
4
- data.tar.gz: de2541ae302b18e5b8662c4eb8407ed2485259ad91b4fd75d3033f680ab47e49
3
+ metadata.gz: 36a1941b8bebb3eef585602735dc05d182dfe09b6ad1f5ba774ddb10790556bb
4
+ data.tar.gz: 549f3f98cc52b1f47aed4b6e7b0152d924a0827c868165ee5ada3099b4e7037d
5
5
  SHA512:
6
- metadata.gz: 75a8ef0381dc3f8e567fc794769c816130234521f63d85865400e7f61564c791b841a0f61dbde08d2249b3a576e350eee08528a6542361d6af9c1564cfd17591
7
- data.tar.gz: 122e35db8b00c5f0fea2605903a1e47048f9190dbc03cb72c78b28923d0c8b69da98b9a7d6841dc19dd33e6f466f451746b435f0235b378ad7d688b39ec39e65
6
+ metadata.gz: a13a3fbcb9b37b09104e8397cf9e13e4e70f0d8fcd3cbc3e879369fb213880d0d3505ede782263702ab0d543197663d6b9000ddd27334a726bdf1695d248fc94
7
+ data.tar.gz: 06e9d53a8ac9d70125ac519835ad128ca3e47b54bef2eb4a5320116b92b294841403fe2c34f966321318c38588dfefea1822f3259f6294414304245459577faa
@@ -4,6 +4,7 @@ module Isomorfeus
4
4
  thread_id_asset = "#{Thread.current.object_id}#{asset}"
5
5
  render_result = "<div data-iso-env=\"#{Isomorfeus.env}\" data-iso-root=\"#{component_name}\" data-iso-props='#{Oj.dump(props, mode: :strict)}'"
6
6
  if Isomorfeus.server_side_rendering
7
+
7
8
  # initialize speednode context
8
9
  unless Isomorfeus.ssr_contexts.key?(thread_id_asset)
9
10
  asset_file_name = OpalWebpackLoader::Manifest.lookup_path_for(asset)
@@ -12,60 +13,66 @@ module Isomorfeus
12
13
  end
13
14
 
14
15
  # build javascript for rendering first pass
15
- javascript = "global.Opal.Isomorfeus['$force_init!']();\n"
16
- if props.key?(:location)
17
- javascript << <<~JAVASCRIPT
18
- global.Opal.Isomorfeus.TopLevel["$ssr_route_path="]('#{props[:location]}');
19
- JAVASCRIPT
20
- end
21
- if props.key?(:location_host) && props.key?(:location_scheme)
22
- ws_scheme = props[:location_scheme] == 'https:' ? 'wss:' : 'ws:'
23
- javascript << <<~JAVASCRIPT
24
- global.Opal.Isomorfeus.TopLevel["$transport_ws_url="]('#{ws_scheme}#{props[:location_host]}#{Isomorfeus.api_websocket_path}');
25
- if (typeof global.Opal.Isomorfeus.Transport !== 'undefined') { global.Opal.Isomorfeus.Transport.$connect(); }
26
- JAVASCRIPT
27
- end
16
+ javascript = "global.FirstPassFinished = false;\n"
17
+ javascript << "global.Opal.Isomorfeus['$force_init!']();\n"
18
+ javascript << "global.Opal.Isomorfeus.TopLevel['$ssr_route_path=']('#{props[:location]}');\n"
19
+
20
+ # if location_host and scheme are given and if Transport is loaded, connect and then render, otherwise do not render
21
+ ws_scheme = props[:location_scheme] == 'https:' ? 'wss:' : 'ws:'
22
+ api_ws_path = Isomorfeus.respond_to?(:api_websocket_path) ? Isomorfeus.api_websocket_path : ''
28
23
  javascript << <<~JAVASCRIPT
29
- var rendered_tree = global.Opal.Isomorfeus.TopLevel.$render_component_to_string('#{component_name}', #{Oj.dump(props, mode: :strict)})
30
- var transport_busy = false;
31
- if (typeof global.Opal.Isomorfeus.Transport !== 'undefined') {
32
- if (typeof global.Opal.Isomorfeus.Transport['$was_busy?'] !== 'undefined') { transport_busy = global.Opal.Isomorfeus.Transport['$was_busy?'](); }
33
- else { transport_busy = global.Opal.Isomorfeus.Transport['$busy?'](); }
34
- if (!transport_busy) { global.Opal.Isomorfeus.Transport.$disconnect(); }
35
- }
36
- if (transport_busy) {
37
- return ['', '', transport_busy]
38
- } else {
39
- var application_state = global.Opal.Isomorfeus.store.native.getState();
40
- return [rendered_tree, application_state, transport_busy];
41
- }
24
+ var location_host = '#{props[:location_host]}';
25
+ var ws_scheme = '#{ws_scheme}';
26
+ var api_ws_path = '#{api_ws_path}';
27
+ if (typeof global.Opal.Isomorfeus.Transport !== 'undefined' && location_host !== '' && api_ws_path !== '') {
28
+ global.Opal.Isomorfeus.TopLevel["$transport_ws_url="](ws_scheme + location_host + api_ws_path);
29
+ global.Opal.send(global.Opal.Isomorfeus.Transport.$promise_connect(), 'then', [], ($$1 = function(){
30
+ try {
31
+ global.Opal.Isomorfeus.TopLevel.$render_component_to_string('#{component_name}', #{Oj.dump(props, mode: :strict)});
32
+ global.FirstPassFinished = 'transport';
33
+ } catch (e) { global.FirstPassFinished = 'transport'; }
34
+ }, $$1.$$s = this, $$1.$$arity = 0, $$1))
35
+ } else { global.FirstPassFinished = true };
42
36
  JAVASCRIPT
37
+
43
38
  # execute first render pass
44
- rendered_tree, application_state, transport_busy = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
39
+ Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
45
40
 
46
- if transport_busy
47
- # wait for transport requests to finish
41
+ # wait for first pass to finish
42
+ first_pass_finished = Isomorfeus.ssr_contexts[thread_id_asset].exec('return global.FirstPassFinished')
43
+ unless first_pass_finished
48
44
  start_time = Time.now
49
- while transport_busy
45
+ while !first_pass_finished
50
46
  break if (Time.now - start_time) > 10
51
47
  sleep 0.01
52
- transport_busy = Isomorfeus.ssr_contexts[thread_id_asset].exec('return global.Opal.Isomorfeus.Transport["$busy?"]()')
48
+ first_pass_finished = Isomorfeus.ssr_contexts[thread_id_asset].exec('return global.FirstPassFinished')
53
49
  end
54
- # build javascript for second render pass
55
- javascript = <<~JAVASCRIPT
56
- var rendered_tree = global.Opal.Isomorfeus.TopLevel.$render_component_to_string('#{component_name}', #{Oj.dump(props, mode: :strict)})
57
- var application_state = global.Opal.Isomorfeus.store.native.getState();
58
- var transport_busy = false;
59
- if (typeof global.Opal.Isomorfeus.Transport !== 'undefined') {
60
- transport_busy = global.Opal.Isomorfeus.Transport['$busy?']();
61
- global.Opal.Isomorfeus.Transport.$disconnect();
62
- }
63
- return [rendered_tree, application_state, transport_busy];
64
- JAVASCRIPT
65
- # execute second render pass
66
- rendered_tree, application_state, _transport_busy = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
67
50
  end
68
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
56
+ start_time = Time.now
57
+ while transport_busy
58
+ break if (Time.now - start_time) > 10
59
+ sleep 0.01
60
+ transport_busy = Isomorfeus.ssr_contexts[thread_id_asset].exec('return global.Opal.Isomorfeus.Transport["$busy?"]()')
61
+ end
62
+ end
63
+ end
64
+
65
+ # build javascript for second render pass
66
+ javascript = <<~JAVASCRIPT
67
+ var rendered_tree = global.Opal.Isomorfeus.TopLevel.$render_component_to_string('#{component_name}', #{Oj.dump(props, mode: :strict)})
68
+ var application_state = global.Opal.Isomorfeus.store.native.getState();
69
+ if (typeof global.Opal.Isomorfeus.Transport !== 'undefined') { global.Opal.Isomorfeus.Transport.$disconnect(); }
70
+ return [rendered_tree, application_state];
71
+ JAVASCRIPT
72
+
73
+ # execute second render pass
74
+ rendered_tree, application_state = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
75
+
69
76
  # build result
70
77
  render_result << " data-iso-state='#{Oj.dump(application_state, mode: :strict)}'>"
71
78
  render_result << rendered_tree
@@ -76,4 +83,4 @@ module Isomorfeus
76
83
  render_result
77
84
  end
78
85
  end
79
- end
86
+ end
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = '16.9.1'
2
+ VERSION = '16.9.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-react
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.9.1
4
+ version: 16.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-11 00:00:00.000000000 Z
11
+ date: 2019-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj