svelte-on-rails 19.2.2 → 19.2.4
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/utils.rb +1 -1
- data/lib/svelte_on_rails/lib/view_helper_support.rb +38 -16
- 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: 0651050b86e2825987db63e71145cf7d2d572530073b5012a2fa2bbeca42befc
|
|
4
|
+
data.tar.gz: 18465ac8ec33e475fb60109ceefe7b9f19d165e298cca6c2ed8c150bef3e7764
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a1839966afa9e6d1a61fdcbb39dd1864571eee64898f15db7294111c07dec2b1eb7b7c8d59290e62cd2b315404430abfe7f0727ba3b6c671b6d4715db93e3345
|
|
7
|
+
data.tar.gz: bd6ad6d60dcda1a6d365aabe5806f808fc74c1e82b6a7070c99be07bad6b14622cc12d4c9d448bafe6a6cfb47a17a5fe2bd812364cc87cac1919df6231c4b9e4
|
|
@@ -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"
|
|
@@ -198,7 +223,7 @@ module SvelteOnRails
|
|
|
198
223
|
:rendered,
|
|
199
224
|
:build_tried_for_error_message
|
|
200
225
|
].include?(action_key)
|
|
201
|
-
raise "[SOR] set_request_metrics: invalid action_key"
|
|
226
|
+
raise "[SOR] set_request_metrics: invalid action_key: #{action_key}"
|
|
202
227
|
end
|
|
203
228
|
|
|
204
229
|
request_metrics
|
|
@@ -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
|
|
@@ -219,8 +244,6 @@ module SvelteOnRails
|
|
|
219
244
|
|
|
220
245
|
if r[:status] == 'SUCCESS'
|
|
221
246
|
set_request_metrics(:build)
|
|
222
|
-
else
|
|
223
|
-
set_request_metrics(:build_failed)
|
|
224
247
|
end
|
|
225
248
|
end
|
|
226
249
|
|
|
@@ -300,10 +323,9 @@ module SvelteOnRails
|
|
|
300
323
|
@cache_key = begin
|
|
301
324
|
fingerprint = (@conf.watch_changes? ? @conf.fingerprint(component_paths[:path], debug?, component_paths[:name]) : '')
|
|
302
325
|
|
|
303
|
-
cache_key_raw = @view_dir + @component_name +
|
|
304
|
-
@
|
|
305
|
-
@
|
|
306
|
-
fingerprint
|
|
326
|
+
cache_key_raw = @view_dir + @component_name + @options.to_s +
|
|
327
|
+
@cached_props.to_s + fingerprint + @options[:cache_key].to_s +
|
|
328
|
+
(@cached_props.key?(:_uncached) ? "" : @html_options.to_s)
|
|
307
329
|
|
|
308
330
|
"#{@conf.redis_namespace}:#{Digest::XXH64.hexdigest(cache_key_raw)}"
|
|
309
331
|
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)
|