svelte-on-rails 19.2.2 → 19.2.3
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/svelte_on_rails/lib/view_helper_support.rb +37 -13
- data/lib/svelte_on_rails/view_helpers.rb +65 -44
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bdd155e6ec85bcd4e50bd36c110a259f3cbe4004331c947a486c976dcf36561f
|
|
4
|
+
data.tar.gz: c2a6b04173b9212f77c4262f26b27e2e0bf14b19f9ef5a109efeaf07690c23cb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e78ba049e517ba2fcae3ae325a1d95a5153c1f20962d17d3a149c7b87133e2442123568ba6b985b6658116434906573133423c2c9bd0a73831092d97400be509
|
|
7
|
+
data.tar.gz: 83393c1c21f7f01aca3d1f071228171ab4b8ab289d7a68183cc5a17a765fa39295ff3629c39cd154b8c912ddc5e50cfc436dcd499abf3539f5b34c8b350bb75a
|
|
@@ -4,7 +4,7 @@ module SvelteOnRails
|
|
|
4
4
|
module Lib
|
|
5
5
|
class ViewHelperSupport
|
|
6
6
|
|
|
7
|
-
UNCACHED_PROPS_PLACEHOLDER = "**
|
|
7
|
+
UNCACHED_PROPS_PLACEHOLDER = "**Uncached Props are available only after hydration**"
|
|
8
8
|
RENDER_OPTIONS = { ssr: [true, false, :auto], hydrate: :bool, debug: :bool, cache_key: :string_array, expires_in: :integer, cached: :bool }
|
|
9
9
|
attr_reader :conf
|
|
10
10
|
|
|
@@ -22,11 +22,11 @@ module SvelteOnRails
|
|
|
22
22
|
@component_name = component
|
|
23
23
|
@view_dir = view_dir
|
|
24
24
|
@request = request
|
|
25
|
-
@
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
@cached_props = if props.key?(:_uncached)
|
|
26
|
+
props.merge(_uncached: UNCACHED_PROPS_PLACEHOLDER)
|
|
27
|
+
else
|
|
28
|
+
props
|
|
29
|
+
end
|
|
30
30
|
@html_options = html_options
|
|
31
31
|
|
|
32
32
|
@ssr = resolve_ssr?(request)
|
|
@@ -157,6 +157,31 @@ module SvelteOnRails
|
|
|
157
157
|
Rails.logger.info " [SOR] #{component_paths[:name]}.svelte #{message} (#{ms.round(1)}ms)"
|
|
158
158
|
end
|
|
159
159
|
|
|
160
|
+
def render_svelte(current_template)
|
|
161
|
+
caller_loc = Proc.new do
|
|
162
|
+
v_path = current_template.identifier
|
|
163
|
+
caller_locations.find { |loc| loc.to_s.include?(v_path) }.to_s.match(/^[\s\S]+(:[0-9]+(?=:in))/).to_s
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
r = if SvelteOnRails::SsrServer.instance.alive?
|
|
167
|
+
SvelteOnRails::SsrServer.instance.render(
|
|
168
|
+
component_paths,
|
|
169
|
+
cached_props,
|
|
170
|
+
debug?,
|
|
171
|
+
caller_loc
|
|
172
|
+
)
|
|
173
|
+
else
|
|
174
|
+
SvelteOnRails::Lib::FallbackRenderer.render(component_paths, cached_props, debug?)
|
|
175
|
+
end
|
|
176
|
+
if r[:success]
|
|
177
|
+
set_request_metrics(:rendered)
|
|
178
|
+
else
|
|
179
|
+
@skip_caching = true
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
r
|
|
183
|
+
end
|
|
184
|
+
|
|
160
185
|
def render_cached(view_context, &block)
|
|
161
186
|
|
|
162
187
|
# increase expired time
|
|
@@ -166,7 +191,7 @@ module SvelteOnRails
|
|
|
166
191
|
# render
|
|
167
192
|
|
|
168
193
|
res = if @cached_content
|
|
169
|
-
msg = "returned from cache#{", with uncached props" if @
|
|
194
|
+
msg = "returned from cache#{", with uncached props" if @cached_props.key?(:_uncached)}"
|
|
170
195
|
@cached_content.html_safe
|
|
171
196
|
else
|
|
172
197
|
msg = "Rendered"
|
|
@@ -208,8 +233,8 @@ module SvelteOnRails
|
|
|
208
233
|
|
|
209
234
|
end
|
|
210
235
|
|
|
211
|
-
def
|
|
212
|
-
@
|
|
236
|
+
def cached_props
|
|
237
|
+
@cached_props ||= {}
|
|
213
238
|
end
|
|
214
239
|
|
|
215
240
|
private
|
|
@@ -300,10 +325,9 @@ module SvelteOnRails
|
|
|
300
325
|
@cache_key = begin
|
|
301
326
|
fingerprint = (@conf.watch_changes? ? @conf.fingerprint(component_paths[:path], debug?, component_paths[:name]) : '')
|
|
302
327
|
|
|
303
|
-
cache_key_raw = @view_dir + @component_name +
|
|
304
|
-
@
|
|
305
|
-
@
|
|
306
|
-
fingerprint
|
|
328
|
+
cache_key_raw = @view_dir + @component_name + @options.to_s +
|
|
329
|
+
@cached_props.to_s + fingerprint + @options[:cache_key].to_s +
|
|
330
|
+
(@cached_props.key?(:_uncached) ? "" : @html_options.to_s)
|
|
307
331
|
|
|
308
332
|
"#{@conf.redis_namespace}:#{Digest::XXH64.hexdigest(cache_key_raw)}"
|
|
309
333
|
end
|
|
@@ -30,24 +30,52 @@ module SvelteOnRails
|
|
|
30
30
|
)
|
|
31
31
|
|
|
32
32
|
if support.ssr?
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
if config.watch_changes? && !config.build_status['passed']
|
|
34
|
+
sor_error_tag(support, wrapper_html, component_props, 'server-side-svelte-build-error', 'SVELTE BUILD FAILED')
|
|
35
|
+
elsif caching
|
|
36
|
+
support.set_request_metrics(:from_cache)
|
|
37
|
+
if component_props.key?(:_uncached)
|
|
38
|
+
|
|
39
|
+
# when we have uncached props, we do not cache the wrapper tag
|
|
40
|
+
|
|
41
|
+
attr = support.tag_attributes(wrapper_html, component_props)
|
|
42
|
+
content_tag(:div, attr) do
|
|
43
|
+
support.render_cached(self) do
|
|
44
|
+
res = support.render_svelte(@current_template)
|
|
45
|
+
if res[:success]
|
|
46
|
+
concat(res[:head].html_safe)
|
|
47
|
+
concat(res[:html].html_safe)
|
|
48
|
+
else
|
|
49
|
+
sor_error_tag(support, wrapper_html, component_props, 'server-side-svelte-render-error', 'SVELTE RENDER FAILED')
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
else
|
|
55
|
+
|
|
56
|
+
# when all props are cached, we can cache the wrapper tag too
|
|
57
|
+
# ... but using only cached props for making sure we don't cache any dynamic content
|
|
58
|
+
|
|
59
|
+
support.render_cached(self) do
|
|
60
|
+
res = support.render_svelte(@current_template)
|
|
61
|
+
if res[:success]
|
|
62
|
+
attr = support.tag_attributes(wrapper_html, support.cached_props)
|
|
63
|
+
content_tag(:div, attr) do
|
|
64
|
+
concat(res[:head].html_safe)
|
|
65
|
+
concat(res[:html].html_safe)
|
|
39
66
|
end
|
|
40
67
|
else
|
|
41
|
-
|
|
42
|
-
support.log_completed("Rendered #{'as empty element that will be mounted on the client side' unless support.ssr?}")
|
|
43
|
-
r
|
|
68
|
+
sor_error_tag(support, wrapper_html, component_props, 'server-side-svelte-render-error', 'SVELTE RENDER FAILED')
|
|
44
69
|
end
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
48
73
|
else
|
|
49
|
-
|
|
74
|
+
r = render_component(support, wrapper_html, component_props)
|
|
75
|
+
support.log_completed("Rendered #{'as empty element that will be mounted on the client side' unless support.ssr?}")
|
|
76
|
+
r
|
|
50
77
|
end
|
|
78
|
+
|
|
51
79
|
else
|
|
52
80
|
render_empty_tag(support, wrapper_html, component_props)
|
|
53
81
|
end
|
|
@@ -57,41 +85,34 @@ module SvelteOnRails
|
|
|
57
85
|
|
|
58
86
|
def render_component(support, html_options, component_props)
|
|
59
87
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
caller_locations.find { |loc| loc.to_s.include?(v_path) }.to_s.match(/^[\s\S]+(:[0-9]+(?=:in))/).to_s
|
|
65
|
-
end
|
|
88
|
+
caller_loc = Proc.new do
|
|
89
|
+
v_path = @current_template.identifier
|
|
90
|
+
caller_locations.find { |loc| loc.to_s.include?(v_path) }.to_s.match(/^[\s\S]+(:[0-9]+(?=:in))/).to_s
|
|
91
|
+
end
|
|
66
92
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
end
|
|
85
|
-
else
|
|
86
|
-
support.instance_variable_set(:@skip_caching, true)
|
|
87
|
-
sor_error_tag(support, html_options, component_props, 'server-side-svelte-render-error', 'SVELTE RENDER FAILED')
|
|
93
|
+
ssr_result = if SvelteOnRails::SsrServer.instance.alive?
|
|
94
|
+
SvelteOnRails::SsrServer.instance.render(
|
|
95
|
+
support.component_paths,
|
|
96
|
+
support.cached_props,
|
|
97
|
+
support.debug?,
|
|
98
|
+
caller_loc
|
|
99
|
+
)
|
|
100
|
+
else
|
|
101
|
+
SvelteOnRails::Lib::FallbackRenderer.render(support.component_paths, support.cached_props, support.debug?)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
if ssr_result[:success]
|
|
105
|
+
support.set_request_metrics(:rendered)
|
|
106
|
+
attr = support.tag_attributes(html_options, component_props)
|
|
107
|
+
content_tag(:div, attr) do
|
|
108
|
+
concat(ssr_result[:head].html_safe)
|
|
109
|
+
concat(ssr_result[:html].html_safe)
|
|
88
110
|
end
|
|
89
|
-
|
|
90
111
|
else
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
112
|
+
support.instance_variable_set(:@skip_caching, true)
|
|
113
|
+
sor_error_tag(support, html_options, component_props, 'server-side-svelte-render-error', 'SVELTE RENDER FAILED')
|
|
94
114
|
end
|
|
115
|
+
|
|
95
116
|
end
|
|
96
117
|
|
|
97
118
|
def render_empty_tag(support, html_options, component_props)
|