isomorfeus-preact 22.9.0.rc7 → 22.9.0.rc9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/browser/delegate_native.rb +6 -18
- data/lib/isomorfeus/preact/config.rb +1 -3
- data/lib/isomorfeus/preact/ssr.rb +1 -1
- data/lib/isomorfeus/preact/thread_local_component_cache.rb +2 -2
- data/lib/isomorfeus/preact/version.rb +1 -1
- data/lib/isomorfeus/preact/view_helper.rb +19 -21
- data/lib/isomorfeus/top_level.rb +8 -11
- data/lib/preact/elements.rb +16 -3
- data/lib/preact.rb +66 -37
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28d9e79cef1f470a18cf3ceb7e24e4b1e87d544bdf3f9ea8e8c466f6e5f135c6
|
4
|
+
data.tar.gz: 0f07f213e0ed7aafb22f7abe64ea41a0b2b1d14dace721dcf01611d19b52f403
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcd883d7865f7b05373510a797cd254fa05fed28f54403c3a6d9c7d9d3ac1e0f51693bca52702b99b0248798339d74dad8a4f178c15611593072a1e5a8eaf6e0
|
7
|
+
data.tar.gz: a937605abfcbe71d93d6d97eb5f6b2783336773dcc7e2a9c3180285d8ccdc6dc011a1d33ba4175d186d6b03a4d47004aa67ad39c57c6f2203bd5e54d63a0bb56
|
@@ -24,29 +24,17 @@ module Browser
|
|
24
24
|
message = message.chop
|
25
25
|
property_name = property_for_message(message)
|
26
26
|
arg = args[0]
|
27
|
-
arg = if `arg && typeof arg.$to_n === 'function'`
|
28
|
-
|
29
|
-
else
|
30
|
-
arg
|
31
|
-
end
|
32
|
-
return `#@native[#{property_name}] = args[0]`
|
27
|
+
arg = arg.to_n if `arg && typeof arg.$to_n === 'function'`
|
28
|
+
return `#@native[#{property_name}] = arg`
|
33
29
|
else
|
34
30
|
property_name = property_for_message(message)
|
35
|
-
|
36
31
|
%x{
|
37
32
|
let value = #@native[#{property_name}];
|
38
33
|
let type = typeof(value);
|
34
|
+
if (type === 'undefined') { return #{super}; }
|
39
35
|
try {
|
40
36
|
if (type === 'function') {
|
41
|
-
#{
|
42
|
-
args.map! do |arg|
|
43
|
-
if `arg && typeof arg.$to_n === 'function'`
|
44
|
-
arg.to_n
|
45
|
-
else
|
46
|
-
arg
|
47
|
-
end
|
48
|
-
end
|
49
|
-
}
|
37
|
+
#{args.map! { |arg| `arg && typeof arg.$to_n === 'function'` ? arg.to_n : arg }}
|
50
38
|
value = value.apply(#@native, args);
|
51
39
|
}
|
52
40
|
if (value instanceof HTMLCollection || value instanceof NodeList) {
|
@@ -69,9 +57,9 @@ module Browser
|
|
69
57
|
end
|
70
58
|
|
71
59
|
def respond_to_missing? message, include_all
|
72
|
-
|
60
|
+
return true if message.end_with? '='
|
73
61
|
property_name = property_for_message(message)
|
74
|
-
return true
|
62
|
+
return true if `#{property_name} in #@native`
|
75
63
|
false
|
76
64
|
end
|
77
65
|
|
@@ -4,7 +4,6 @@ module Isomorfeus
|
|
4
4
|
attr_accessor :browser_history
|
5
5
|
attr_accessor :browser_location
|
6
6
|
attr_accessor :current_user_sid_s
|
7
|
-
attr_accessor :initial_state_fetched
|
8
7
|
attr_accessor :ssr_response_status
|
9
8
|
attr_accessor :top_component
|
10
9
|
attr_reader :initialized
|
@@ -29,8 +28,7 @@ module Isomorfeus
|
|
29
28
|
end
|
30
29
|
|
31
30
|
def force_render
|
32
|
-
|
33
|
-
Preact.unmount_component_at_node(root_element)
|
31
|
+
Preact.unmount_component_at_node(`document.body`)
|
34
32
|
Isomorfeus::TopLevel.do_the_mount!(init: false)
|
35
33
|
nil
|
36
34
|
rescue Exception => e
|
@@ -10,7 +10,7 @@ module Isomorfeus
|
|
10
10
|
|
11
11
|
def render(skip_ssr)
|
12
12
|
Isomorfeus.browser_location = Browser::Location.new(@location)
|
13
|
-
Isomorfeus.current_locale = @locale
|
13
|
+
Isomorfeus.current_locale = @locale if @locale
|
14
14
|
NanoCSS.instance = NanoCSS.new(given_renderer: NanoCSS.global_instance.renderer.deep_dup)
|
15
15
|
Isomorfeus.init_store
|
16
16
|
Isomorfeus.store.clear!
|
@@ -8,8 +8,8 @@ module Isomorfeus
|
|
8
8
|
Thread.current[:local_cache][key]
|
9
9
|
end
|
10
10
|
|
11
|
-
def store(key, rendered_tree,
|
12
|
-
Thread.current[:local_cache][key] = [rendered_tree,
|
11
|
+
def store(key, rendered_tree, styles, data, status)
|
12
|
+
Thread.current[:local_cache][key] = [rendered_tree, styles, data, status]
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -13,36 +13,42 @@ module Preact
|
|
13
13
|
end
|
14
14
|
render_result = mount_component(component_name, props, asset_key, skip_ssr: skip_ssr)
|
15
15
|
status = ssr_response_status
|
16
|
-
component_cache.store(key, render_result, ssr_styles, status) if status >= 200 && status < 300
|
16
|
+
component_cache.store(key, render_result, ssr_styles, ssr_data, status) if status >= 200 && status < 300
|
17
17
|
render_result
|
18
18
|
end
|
19
19
|
|
20
20
|
def mount_component(component_name, props = {}, skip_ssr: false)
|
21
21
|
ssr_start_time = Time.now if Isomorfeus.development?
|
22
|
-
@ssr_styles = nil
|
23
22
|
locale = props.delete(:locale)
|
24
|
-
render_result = "<div data-iso-env=\"#{Isomorfeus.env}\" data-iso-root=\"#{component_name}\" data-iso-props='#{Oj.dump(props, mode: :strict)}'"
|
25
23
|
location_host = props[:location_host] ? props[:location_host] : 'localhost'
|
26
24
|
location = "#{props[:location_scheme] || 'http:'}//#{location_host}#{props[:location]}"
|
27
25
|
|
28
26
|
rendered_tree, application_state, @_ssr_styles = Isomorfeus::TopLevel.mount_component(component_name, props, Thread.current[:isomorfeus_session_id], location, locale, skip_ssr)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
27
|
+
component_name = component_name.to_s unless component_name.is_a?(String)
|
28
|
+
usids = if Isomorfeus.respond_to?(:current_user) && Isomorfeus.current_user && !Isomorfeus.current_user.anonymous?
|
29
|
+
Isomorfeus.current_user.sid.to_s
|
30
|
+
else
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
@_ssr_data = <<~HTML
|
35
|
+
<script type='application/javascript'>
|
36
|
+
ServerSideRenderingStateJSON = #{Oj.dump(application_state, mode: :strict)}
|
37
|
+
ServerSideRenderingProps = #{Oj.dump({ env: Isomorfeus.env, component_name: component_name, props: props, hydrated: !skip_ssr, usids: usids }, mode: :strict)}
|
38
|
+
</script>
|
39
|
+
HTML
|
38
40
|
puts "Preact::ViewHelper Server Side Rendering took ~#{((Time.now - ssr_start_time)*1000).to_i}ms" if Isomorfeus.development?
|
39
|
-
|
41
|
+
rendered_tree ? rendered_tree : "SSR didn't work"
|
40
42
|
end
|
41
43
|
|
42
44
|
def ssr_response_status
|
43
45
|
Isomorfeus.ssr_response_status
|
44
46
|
end
|
45
47
|
|
48
|
+
def ssr_data
|
49
|
+
@_ssr_data
|
50
|
+
end
|
51
|
+
|
46
52
|
def ssr_styles
|
47
53
|
@_ssr_styles || ''
|
48
54
|
end
|
@@ -52,13 +58,5 @@ module Preact
|
|
52
58
|
def component_cache
|
53
59
|
@_component_cache ||= Isomorfeus.component_cache_init_block.call
|
54
60
|
end
|
55
|
-
|
56
|
-
def ssr_mod
|
57
|
-
@_ssr_mod ||= Opal.compile(File.read(File.expand_path(File.join(File.dirname(__FILE__), 'ssr.rb'))), { use_strict: true })
|
58
|
-
end
|
59
|
-
|
60
|
-
def top_level_mod
|
61
|
-
@_top_level_mod ||= Opal.compile(File.read(File.expand_path(File.join(File.dirname(__FILE__), 'top_level_ssr.rb'))), { use_strict: true })
|
62
|
-
end
|
63
61
|
end
|
64
62
|
end
|
data/lib/isomorfeus/top_level.rb
CHANGED
@@ -7,11 +7,10 @@ module Isomorfeus
|
|
7
7
|
if RUBY_ENGINE == 'opal'
|
8
8
|
def do_the_mount!(init: true)
|
9
9
|
NanoCSS.instance = NanoCSS.new({ sh: `document.getElementById('css-server-side')` })
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
Isomorfeus.
|
14
|
-
Isomorfeus.current_user_sid_s = root_element.JS.getAttribute('data-iso-usids')
|
10
|
+
p = `global.ServerSideRenderingProps`
|
11
|
+
component_name = p.JS[:component_name]
|
12
|
+
Isomorfeus.env = p.JS[:env]
|
13
|
+
Isomorfeus.current_user_sid_s = p.JS[:usids]
|
15
14
|
component = nil
|
16
15
|
begin
|
17
16
|
component = component_name.constantize
|
@@ -29,14 +28,12 @@ module Isomorfeus
|
|
29
28
|
end
|
30
29
|
end
|
31
30
|
if component
|
32
|
-
|
33
|
-
props = JSON.parse(props_json)
|
31
|
+
props = Hash.new(p.JS[:props])
|
34
32
|
if init
|
35
|
-
|
36
|
-
Isomorfeus::TopLevel.hydrated = (raw_hydrated && raw_hydrated == "true")
|
33
|
+
Isomorfeus::TopLevel.hydrated = p.JS[:hydrated]
|
37
34
|
%x{
|
38
|
-
if (global.ServerSideRenderingStateJSON) {
|
39
35
|
var state = global.ServerSideRenderingStateJSON;
|
36
|
+
if (state) {
|
40
37
|
var keys = Object.keys(state);
|
41
38
|
for(var i=0; i < keys.length; i++) {
|
42
39
|
if (Object.keys(state[keys[i]]).length > 0) {
|
@@ -49,7 +46,7 @@ module Isomorfeus
|
|
49
46
|
end
|
50
47
|
begin
|
51
48
|
Isomorfeus::TopLevel.first_pass = true
|
52
|
-
result = Isomorfeus::TopLevel.mount_component(component, props,
|
49
|
+
result = Isomorfeus::TopLevel.mount_component(component, props, `document.body`, Isomorfeus::TopLevel.hydrated)
|
53
50
|
Isomorfeus::TopLevel.first_pass = false
|
54
51
|
@tried_another_time = false
|
55
52
|
result
|
data/lib/preact/elements.rb
CHANGED
@@ -45,9 +45,22 @@ module Preact::Elements
|
|
45
45
|
view vkern
|
46
46
|
]
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
if RUBY_ENGINE == 'opal'
|
49
|
+
SUPPORTED_HTML_AND_SVG_ELEMENTS.each do |element|
|
50
|
+
define_method(element.underscore.upcase) do |props = nil, &block|
|
51
|
+
%x{
|
52
|
+
const op = Opal.Preact;
|
53
|
+
const opr = op.render_buffer;
|
54
|
+
if (typeof block === 'function') op.$create_element.$$p = block.$to_proc();
|
55
|
+
opr[opr.length-1].push(op.$create_element(element, props, nil));
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
else
|
60
|
+
SUPPORTED_HTML_AND_SVG_ELEMENTS.each do |element|
|
61
|
+
define_method(element.to_s.underscore.upcase.to_sym) do |props = nil, &block|
|
62
|
+
Preact._render_element(element, props, &block)
|
63
|
+
end
|
51
64
|
end
|
52
65
|
end
|
53
66
|
|
data/lib/preact.rb
CHANGED
@@ -1188,43 +1188,6 @@ module Preact
|
|
1188
1188
|
end
|
1189
1189
|
end
|
1190
1190
|
|
1191
|
-
def create_element(type, props = nil, children = nil, &block)
|
1192
|
-
if props
|
1193
|
-
if props.is_a?(Hash)
|
1194
|
-
normalized_props = props.dup
|
1195
|
-
key = normalized_props.delete(:key)
|
1196
|
-
ref = normalized_props.delete(:ref)
|
1197
|
-
else
|
1198
|
-
children = props
|
1199
|
-
normalized_props = {}
|
1200
|
-
key = nil
|
1201
|
-
ref = nil
|
1202
|
-
end
|
1203
|
-
else
|
1204
|
-
normalized_props = {}
|
1205
|
-
key = nil
|
1206
|
-
ref = nil
|
1207
|
-
end
|
1208
|
-
|
1209
|
-
if block_given?
|
1210
|
-
pr = render_buffer
|
1211
|
-
pr.push([])
|
1212
|
-
block_result = block.call
|
1213
|
-
children = pr.pop
|
1214
|
-
if Preact.is_renderable?(block_result)
|
1215
|
-
children.push(block_result)
|
1216
|
-
end
|
1217
|
-
end
|
1218
|
-
|
1219
|
-
normalized_props[:children] = children unless children.nil?
|
1220
|
-
|
1221
|
-
if RUBY_ENGINE == 'opal'
|
1222
|
-
`self.createVNode(type, normalized_props, key, ref, null)`
|
1223
|
-
else
|
1224
|
-
_create_vnode(type, normalized_props, key, ref, nil)
|
1225
|
-
end
|
1226
|
-
end
|
1227
|
-
|
1228
1191
|
def create_context(const_name, default_value = nil)
|
1229
1192
|
context = Preact::Context.new(default_value)
|
1230
1193
|
Object.const_set(const_name, context)
|
@@ -1247,6 +1210,40 @@ module Preact
|
|
1247
1210
|
attr_accessor :render_buffer
|
1248
1211
|
attr_accessor :rerender_queue
|
1249
1212
|
|
1213
|
+
def create_element(type, props = nil, children = nil, &block)
|
1214
|
+
if props
|
1215
|
+
if props.is_a?(Hash)
|
1216
|
+
normalized_props = props.dup
|
1217
|
+
key = normalized_props.delete(:key)
|
1218
|
+
ref = normalized_props.delete(:ref)
|
1219
|
+
else
|
1220
|
+
children = props
|
1221
|
+
normalized_props = {}
|
1222
|
+
key = nil
|
1223
|
+
ref = nil
|
1224
|
+
end
|
1225
|
+
else
|
1226
|
+
normalized_props = {}
|
1227
|
+
key = nil
|
1228
|
+
ref = nil
|
1229
|
+
end
|
1230
|
+
|
1231
|
+
if block_given?
|
1232
|
+
pr = render_buffer
|
1233
|
+
pr.JS.push([])
|
1234
|
+
block_result = block.call
|
1235
|
+
children = pr.JS.pop()
|
1236
|
+
if Preact.is_renderable?(block_result)
|
1237
|
+
children.JS.push(block_result)
|
1238
|
+
end
|
1239
|
+
end
|
1240
|
+
|
1241
|
+
%x{
|
1242
|
+
if (children !== nil && children !== null) { #{normalized_props[:children] = children} }
|
1243
|
+
return self.createVNode(type, normalized_props, key, ref, null);
|
1244
|
+
}
|
1245
|
+
end
|
1246
|
+
|
1250
1247
|
def _enqueue_render(c)
|
1251
1248
|
if ((`!c._dirty` && (`c._dirty = true`) && rerender_queue.push(c) && `!self.process._rerenderCount++`))
|
1252
1249
|
`setTimeout(self.process)`
|
@@ -1321,6 +1318,38 @@ module Preact
|
|
1321
1318
|
VNode.new(type, props, key, ref, original)
|
1322
1319
|
end
|
1323
1320
|
|
1321
|
+
def create_element(type, props = nil, children = nil, &block)
|
1322
|
+
if props
|
1323
|
+
if props.is_a?(Hash)
|
1324
|
+
normalized_props = props.dup
|
1325
|
+
key = normalized_props.delete(:key)
|
1326
|
+
ref = normalized_props.delete(:ref)
|
1327
|
+
else
|
1328
|
+
children = props
|
1329
|
+
normalized_props = {}
|
1330
|
+
key = nil
|
1331
|
+
ref = nil
|
1332
|
+
end
|
1333
|
+
else
|
1334
|
+
normalized_props = {}
|
1335
|
+
key = nil
|
1336
|
+
ref = nil
|
1337
|
+
end
|
1338
|
+
|
1339
|
+
if block_given?
|
1340
|
+
pr = render_buffer
|
1341
|
+
pr.push([])
|
1342
|
+
block_result = block.call
|
1343
|
+
children = pr.pop
|
1344
|
+
if Preact.is_renderable?(block_result)
|
1345
|
+
children.push(block_result)
|
1346
|
+
end
|
1347
|
+
end
|
1348
|
+
|
1349
|
+
normalized_props[:children] = children unless children.nil?
|
1350
|
+
_create_vnode(type, normalized_props, key, ref, nil)
|
1351
|
+
end
|
1352
|
+
|
1324
1353
|
def _encode_entities(input)
|
1325
1354
|
s = input.to_s
|
1326
1355
|
return s unless ENCODED_ENTITIES.match?(s)
|
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: 22.9.0.
|
4
|
+
version: 22.9.0.rc9
|
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-09-
|
11
|
+
date: 2022-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -58,28 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 22.9.0.
|
61
|
+
version: 22.9.0.rc9
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 22.9.0.
|
68
|
+
version: 22.9.0.rc9
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: isomorfeus-redux
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 22.9.0.
|
75
|
+
version: 22.9.0.rc9
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 22.9.0.
|
82
|
+
version: 22.9.0.rc9
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: isomorfeus-puppetmaster
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|