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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71f0e2e4c50dfd7a41114cd679fcef0288f3003b774e0cf78c73f99f130a5960
4
- data.tar.gz: 31c4fed1aaa9bc3d239ca97fe78b8d6355220c1213bf9c9e9aa0442075b2e5f0
3
+ metadata.gz: c6aa16242ab93d05f360dd9c8b3455dd2e4b4084835116cd8973356edde20d4c
4
+ data.tar.gz: b230de356c9524d886f9cbfed54edc39c5531d7531b205301358c19acb800809
5
5
  SHA512:
6
- metadata.gz: 4ad75f6d1bcee7758a87bfa9a5e8ea27ee87d1fbd7848b1c2d70365445ec05b27ece212da80019b3d493ebd2f2c474bed51c91fb20e4bdf26cfd32c2e21fb2af
7
- data.tar.gz: e001b19a26bf518fd86562ad5542a472ac382b6d9779817564e87e256a7e7a19ac657c2947d9603b06ccf97f85d21bd31e61c3cade9dd05109dc5f6bc21112c5
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
- unless Isomorfeus.initial_state_fetched
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
- Isomorfeus.raise_error(message: "Server Side Rendering: Failed creating context for #{asset_key}. Error: #{e.message}", stack: e.backtrace)
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, has_store, need_further_pass, exception = ctx.exec(javascript)
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 && has_store
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
- nil
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
- need_further_pass = ctx.eval_script(key: script_key)
114
- while need_further_pass
115
- break if (Time.now - start_time) > 4
116
- sleep 0.01
117
- need_further_pass = ctx.eval_script(key: script_key)
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: 'let nfp = global.Opal.Isomorfeus.Transport["$busy?"]() || global.Opal.Isomorfeus.store["$recently_dispatched?"](); (nfp == global.Opal.nil) ? false : nfp;')
183
- ctx.add_script(key: :store_busy, source: 'let nfp = global.Opal.Isomorfeus.store["$recently_dispatched?"](); (nfp == global.Opal.nil) ? false : nfp;')
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.Transport.$disconnect()')
185
+ ctx.add_script(key: :transport_disconnect, source: 'global.Opal.Isomorfeus.SSR.$disconnect_transport()')
186
186
  end
187
187
  end
188
188
 
@@ -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
- let nfp = global.Opal.Isomorfeus.Transport["$busy?"]() || global.Opal.Isomorfeus.store['$recently_dispatched?']();
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
- if (global.HasStore) {
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.HasStore, global.NeedFurtherPass, global.Exception ? { message: global.Exception.message, stack: global.Exception.stack } : false];
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
- let nfp = (global.HasTransport && global.Opal.Isomorfeus.Transport["$busy?"]()) || (global.HasStore && global.Opal.Isomorfeus.store["$recently_dispatched?"]());
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 = Isomorfeus.cached_component_class(component_name) unless 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
@@ -1,3 +1,3 @@
1
1
  module Preact
2
- VERSION = '10.6.42'
2
+ VERSION = '10.6.46'
3
3
  end
data/lib/preact.rb CHANGED
@@ -294,11 +294,7 @@ module Preact
294
294
  end
295
295
  end
296
296
 
297
- if on_ssr?
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.42
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-20 00:00:00.000000000 Z
11
+ date: 2022-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby