isomorfeus-react 16.9.4 → 16.9.5

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: 130e5c42bf50ff422d94f269e43b5339eae2364cb44d5bcfb1a288ac6e19350e
4
- data.tar.gz: fd5573839b4c89edceda8ebe29bf8e202e53bc6cafc59b8b5d1d66b19420d321
3
+ metadata.gz: 2bb389b00cc336750921d6f9cbed09d122e248b5502c1133720fb3be193d1fe1
4
+ data.tar.gz: d189a0b592d10ac2e4817e674930f6e5e01174dd4d9f7b37796126ce4015660d
5
5
  SHA512:
6
- metadata.gz: ee586d6c9b6e3119f2426a392b2b0f84d7a68634e03b663ddf10f5399d0213494d051d9c6cdf8d6b4fdb964f3cc709455b410e70d289afa8639d209c55baa4ce
7
- data.tar.gz: d3aa97bd524eb1d71c27a42c750cd1edda3b7dd5b23b4817c2f3116561bacb12d3c4224d2f239619c2296a544e26c2ffafa57b0e5475af25e2e621d43413c734
6
+ metadata.gz: 3a504977c3f5ab42da8519b925b672b5b1129ac1d806a466a35f3162f124f25729498cc381c5d3a0272aa3bca0ff65892bce38d7efc9921e49733391658a2141
7
+ data.tar.gz: ba2e69d7f98e2c6f706dd0bb40f96fbbe34f2c08aa48a6e03fda0c95be9afdfc45f9ff8cb38349b57dfb89592efa4c40433dfb8bf6443754e765a3c24469a225
@@ -3,6 +3,7 @@ module Isomorfeus
3
3
  class << self
4
4
  attr_accessor :initial_state_fetched
5
5
  attr_accessor :top_component
6
+ attr_accessor :ssr_response_status
6
7
  attr_reader :initialized
7
8
  attr_reader :env
8
9
 
@@ -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 = "global.FirstPassFinished = false;\n"
17
- javascript << "global.Opal.Isomorfeus['$force_init!']();\n"
18
- javascript << "global.Opal.Isomorfeus.TopLevel['$ssr_route_path=']('#{props[:location]}');\n"
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
- first_pass_finished = Isomorfeus.ssr_contexts[thread_id_asset].exec('return global.FirstPassFinished')
43
- unless first_pass_finished
44
- start_time = Time.now
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 transport_busy
50
+ while !first_pass_finished
58
51
  break if (Time.now - start_time) > 10
59
52
  sleep 0.01
60
- transport_busy = Isomorfeus.ssr_contexts[thread_id_asset].exec('return global.Opal.Isomorfeus.Transport["$busy?"]()')
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
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = '16.9.4'
2
+ VERSION = '16.9.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-react
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.9.4
4
+ version: 16.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann