isomorfeus-preact 10.6.21 → 10.6.25
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/browser/delegate_native.rb +16 -6
- data/lib/isomorfeus/preact_view_helper.rb +30 -8
- data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +4 -2
- data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +4 -2
- data/lib/preact/component/native_component_constructor.rb +10 -4
- data/lib/preact/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5297a6babb3f48a4cebfe2a957fdfcb8b3e3e7de5a928956e0b93f7d3d2741c8
|
|
4
|
+
data.tar.gz: a2af099fbf9f129b1fb6054249c99b6387b79ad4ea10493f9b481672afdc8ed2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4098d558db9b42dc5c35ae1602c83829a80ae64e986fb9f843af1321cec415b314acee4ac292b3c891628b4fc7b1b8628605561a7858af5d5e18d8a6c0d2ad3
|
|
7
|
+
data.tar.gz: c726635dc08b8e506551e3e28ada187bd1327bbe30bad51f4095b56e242b412db83d0028c4d33a9608f958986b04d4b8ad090ebff40862d1776db01beb261cc7
|
|
@@ -26,12 +26,22 @@ module Browser
|
|
|
26
26
|
%x{
|
|
27
27
|
let value = #@native[#{property_name}];
|
|
28
28
|
let type = typeof(value);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
try {
|
|
30
|
+
if (type === 'function') {
|
|
31
|
+
return value.apply(#@native, args);
|
|
32
|
+
} else if (type === 'object' && (value instanceof HTMLCollection)) {
|
|
33
|
+
let a = [];
|
|
34
|
+
for(let i=0; i<value.length; i++) {
|
|
35
|
+
a[i] = #{Browser::Element.new(`value.item(i)`)};
|
|
36
|
+
}
|
|
37
|
+
value = a;
|
|
38
|
+
} else if (type === 'object' && (value instanceof HTMLElement)) {
|
|
39
|
+
value = #{Browser::Element.new(value)};
|
|
40
|
+
} else if (value === null || type === 'undefined' || (type === 'number' && isNaN(value))) {
|
|
41
|
+
return nil;
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
} catch { return value; }
|
|
35
45
|
}
|
|
36
46
|
end
|
|
37
47
|
end
|
|
@@ -4,19 +4,19 @@ module Isomorfeus
|
|
|
4
4
|
base.include Isomorfeus::AssetManager::ViewHelper
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
def cached_mount_component(component_name, props = {}, asset_key = 'ssr.js')
|
|
7
|
+
def cached_mount_component(component_name, props = {}, asset_key = 'ssr.js', skip_ssr: false, use_ssr: false, max_passes: 4)
|
|
8
8
|
key = "#{component_name}#{props}#{asset}"
|
|
9
9
|
if Isomorfeus.production?
|
|
10
10
|
render_result, @ssr_response_status, @ssr_styles = component_cache.fetch(key)
|
|
11
11
|
return render_result if render_result
|
|
12
12
|
end
|
|
13
|
-
render_result = mount_component(component_name, props, asset_key)
|
|
13
|
+
render_result = mount_component(component_name, props, asset_key, skip_ssr: skip_ssr, use_ssr: use_ssr, max_passes: max_passes)
|
|
14
14
|
status = ssr_response_status
|
|
15
15
|
component_cache.store(key, render_result, status, ssr_styles) if status >= 200 && status < 300
|
|
16
16
|
render_result
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
def mount_component(component_name, props = {}, asset_key = 'ssr.js', skip_ssr: false, use_ssr: false)
|
|
19
|
+
def mount_component(component_name, props = {}, asset_key = 'ssr.js', skip_ssr: false, use_ssr: false, max_passes: 4)
|
|
20
20
|
@ssr_response_status = nil
|
|
21
21
|
@ssr_styles = nil
|
|
22
22
|
thread_id_asset = "#{Thread.current.object_id}#{asset_key}"
|
|
@@ -41,6 +41,8 @@ module Isomorfeus
|
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
start_time = Time.now if Isomorfeus.development?
|
|
45
|
+
pass = 1
|
|
44
46
|
# if location_host and scheme are given and if Transport is loaded, connect and then render,
|
|
45
47
|
# otherwise do not render because only one pass is required
|
|
46
48
|
ws_scheme = props[:location_scheme] == 'https:' ? 'wss:' : 'ws:'
|
|
@@ -88,6 +90,7 @@ module Isomorfeus
|
|
|
88
90
|
end
|
|
89
91
|
# wait for first pass to finish
|
|
90
92
|
unless first_pass_skipped
|
|
93
|
+
pass += 1
|
|
91
94
|
first_pass_finished, exception = Isomorfeus.ssr_contexts[thread_id_asset].exec('return [global.FirstPassFinished, global.Exception ? { message: global.Exception.message, stack: global.Exception.stack } : false ]')
|
|
92
95
|
Isomorfeus.raise_error(message: "Server Side Rendering: #{exception['message']}", stack: exception['stack']) if exception
|
|
93
96
|
unless first_pass_finished
|
|
@@ -104,7 +107,7 @@ module Isomorfeus
|
|
|
104
107
|
if transport_busy
|
|
105
108
|
start_time = Time.now
|
|
106
109
|
while transport_busy
|
|
107
|
-
break if (Time.now - start_time) >
|
|
110
|
+
break if (Time.now - start_time) > 5
|
|
108
111
|
sleep 0.01
|
|
109
112
|
transport_busy = Isomorfeus.ssr_contexts[thread_id_asset].exec('return global.Opal.Isomorfeus.Transport["$busy?"]()')
|
|
110
113
|
end
|
|
@@ -127,12 +130,30 @@ module Isomorfeus
|
|
|
127
130
|
global.Exception = e;
|
|
128
131
|
}
|
|
129
132
|
let application_state = global.Opal.Isomorfeus.store.native.getState();
|
|
130
|
-
|
|
133
|
+
let transport_busy = false;
|
|
134
|
+
if (typeof global.Opal.Isomorfeus.Transport !== 'undefined' && global.Opal.Isomorfeus.Transport["$busy?"]()) { transport_busy = true; }
|
|
131
135
|
if (typeof global.NanoCSSInstance !== 'undefined') { ssr_styles = global.NanoCSSInstance.raw }
|
|
132
|
-
return [rendered_tree, application_state, ssr_styles, global.Opal.Isomorfeus['$ssr_response_status'](), global.Exception ? { message: global.Exception.message, stack: global.Exception.stack } : false];
|
|
136
|
+
return [rendered_tree, application_state, ssr_styles, global.Opal.Isomorfeus['$ssr_response_status'](), transport_busy, global.Exception ? { message: global.Exception.message, stack: global.Exception.stack } : false];
|
|
137
|
+
JAVASCRIPT
|
|
138
|
+
# execute further render passes
|
|
139
|
+
rendered_tree, application_state, @ssr_styles, @ssr_response_status, transport_busy, exception = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
|
|
140
|
+
start_time = Time.now
|
|
141
|
+
while transport_busy
|
|
142
|
+
break if (Time.now - start_time) > 5
|
|
143
|
+
while transport_busy
|
|
144
|
+
break if (Time.now - start_time) > 4
|
|
145
|
+
sleep 0.01
|
|
146
|
+
transport_busy = Isomorfeus.ssr_contexts[thread_id_asset].exec('return global.Opal.Isomorfeus.Transport["$busy?"]()')
|
|
147
|
+
end
|
|
148
|
+
# execute third render pass
|
|
149
|
+
pass += 1
|
|
150
|
+
rendered_tree, application_state, @ssr_styles, @ssr_response_status, transport_busy, exception = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
|
|
151
|
+
break if pass > max_passes
|
|
152
|
+
end
|
|
153
|
+
javascript = <<~JAVASCRIPT
|
|
154
|
+
if (typeof global.Opal.Isomorfeus.Transport !== 'undefined') { global.Opal.Isomorfeus.Transport.$disconnect(); }
|
|
133
155
|
JAVASCRIPT
|
|
134
|
-
|
|
135
|
-
rendered_tree, application_state, @ssr_styles, @ssr_response_status, exception = Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
|
|
156
|
+
Isomorfeus.ssr_contexts[thread_id_asset].exec(javascript)
|
|
136
157
|
Isomorfeus.raise_error(message: exception['message'], stack: exception['stack']) if exception
|
|
137
158
|
render_result << " data-iso-hydrated='true'" if rendered_tree
|
|
138
159
|
if Isomorfeus.respond_to?(:current_user) && Isomorfeus.current_user && !Isomorfeus.current_user.anonymous?
|
|
@@ -150,6 +171,7 @@ module Isomorfeus
|
|
|
150
171
|
if Isomorfeus.server_side_rendering
|
|
151
172
|
render_result = "<script type='application/javascript'>\nServerSideRenderingStateJSON = #{Oj.dump(application_state, mode: :strict)}\n</script>\n" << render_result
|
|
152
173
|
end
|
|
174
|
+
STDERR.puts "PreactViewHelper Server Side Rendering rendered #{pass} passes and took ~#{Time.now - start_time}s" if Isomorfeus.development?
|
|
153
175
|
render_result
|
|
154
176
|
end
|
|
155
177
|
|
|
@@ -36,7 +36,9 @@ module LucidApp
|
|
|
36
36
|
let r = ref; // to ensure closure for function below gets correct ref name
|
|
37
37
|
this[ref] = function(element) {
|
|
38
38
|
element = oper.native_element_or_component_to_ruby(element);
|
|
39
|
+
oper.register_active_component(this);
|
|
39
40
|
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
|
|
41
|
+
oper.unregister_active_component(this);
|
|
40
42
|
}
|
|
41
43
|
this[ref] = this[ref].bind(this);
|
|
42
44
|
} else {
|
|
@@ -44,9 +46,9 @@ module LucidApp
|
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
if (base.preload_block) {
|
|
47
|
-
oper.
|
|
49
|
+
oper.register_active_component(this);
|
|
48
50
|
this.state.preloaded = this.__ruby_instance.$execute_preload_block();
|
|
49
|
-
oper.
|
|
51
|
+
oper.unregister_active_component(this);
|
|
50
52
|
}
|
|
51
53
|
this.listener = this.listener.bind(this);
|
|
52
54
|
this.unsubscriber = Opal.Isomorfeus.store.native.subscribe(this.listener);
|
|
@@ -32,7 +32,9 @@ module LucidComponent
|
|
|
32
32
|
let r = ref; // to ensure closure for function below gets correct ref name
|
|
33
33
|
this[ref] = function(element) {
|
|
34
34
|
element = oper.native_element_or_component_to_ruby(element);
|
|
35
|
+
oper.register_active_component(this);
|
|
35
36
|
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
|
|
37
|
+
oper.unregister_active_component(this);
|
|
36
38
|
}
|
|
37
39
|
this[ref] = this[ref].bind(this);
|
|
38
40
|
} else {
|
|
@@ -40,9 +42,9 @@ module LucidComponent
|
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
if (base.preload_block) {
|
|
43
|
-
oper.
|
|
45
|
+
oper.register_active_component(this);
|
|
44
46
|
this.state.preloaded = this.__ruby_instance.$execute_preload_block();
|
|
45
|
-
oper.
|
|
47
|
+
oper.unregister_active_component(this);
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
static get displayName() {
|
|
@@ -21,8 +21,11 @@ module Preact
|
|
|
21
21
|
if (defined_refs[ref] != null) {
|
|
22
22
|
let r = ref; // to ensure closure for function below gets correct ref name
|
|
23
23
|
this[ref] = function(element) {
|
|
24
|
-
|
|
24
|
+
const oper = Opal.Preact;
|
|
25
|
+
element = oper.native_element_or_component_to_ruby(element);
|
|
26
|
+
oper.register_active_component(this);
|
|
25
27
|
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
|
|
28
|
+
oper.unregister_active_component(this);
|
|
26
29
|
}
|
|
27
30
|
this[ref] = this[ref].bind(this);
|
|
28
31
|
} else {
|
|
@@ -44,11 +47,14 @@ module Preact
|
|
|
44
47
|
return (result.length === 1) ? result[0] : result;
|
|
45
48
|
}
|
|
46
49
|
shouldComponentUpdate(next_props, next_state) {
|
|
50
|
+
const oper = Opal.Preact;
|
|
47
51
|
if (base.should_component_update_block) {
|
|
48
|
-
|
|
52
|
+
oper.register_active_component(this);
|
|
53
|
+
return #{!!`this.__ruby_instance`.instance_exec(`oper.Props.$new({props: next_props})`, `oper.State.$new({state: next_state })`, &`base.should_component_update_block`)};
|
|
54
|
+
oper.unregister_active_component(this);
|
|
49
55
|
}
|
|
50
|
-
if (!
|
|
51
|
-
if (
|
|
56
|
+
if (!oper.props_are_equal(this.props, next_props)) { return true; }
|
|
57
|
+
if (oper.state_is_not_equal(this.state, next_state)) { return true; }
|
|
52
58
|
return false;
|
|
53
59
|
}
|
|
54
60
|
validateProp(props, propName, componentName) {
|
data/lib/preact/version.rb
CHANGED
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.25
|
|
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-
|
|
11
|
+
date: 2022-02-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: concurrent-ruby
|
|
@@ -86,14 +86,14 @@ dependencies:
|
|
|
86
86
|
requirements:
|
|
87
87
|
- - "~>"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: 0.14.
|
|
89
|
+
version: 0.14.8
|
|
90
90
|
type: :runtime
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: 0.14.
|
|
96
|
+
version: 0.14.8
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: isomorfeus-redux
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|