view_component 4.16.0 → 4.17.0
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/docs/CHANGELOG.md +14 -0
- data/lib/view_component/compile_cache.rb +9 -0
- data/lib/view_component/engine.rb +15 -2
- data/lib/view_component/translatable.rb +7 -12
- data/lib/view_component/version.rb +1 -1
- 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: 49aef67be789faf45059eeab902b02dcc50197a5b2da2482306966f809c3a2a3
|
|
4
|
+
data.tar.gz: e8bab208c38f90f778eef18ba4f2f9a41593c88b4332870b537d11deaafcb647
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 786b0a2c41adef88d25b11755a567b9adc356830ea2d23e9eb16b20d2882c38cbee10c0c14a6b2e052363f200b5493bdca493fdda87c514a109c93fac8501cb6
|
|
7
|
+
data.tar.gz: 7eb9c8c3234baf98fd725cdaf0d9ceae6a083f068bb043ed12b8db4162666370e4ad70f449adc5477c056dc72d12f6850090933579944480fd7618b2e3c0b51a
|
data/docs/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,20 @@ nav_order: 6
|
|
|
10
10
|
|
|
11
11
|
## main
|
|
12
12
|
|
|
13
|
+
## 4.17.0
|
|
14
|
+
|
|
15
|
+
* Only register the executor hook that watches component templates when Action View doesn't cache templates at boot. With template caching on, as in production, the hook did nothing but still read `ActionView::Base.cache_template_loading` on every request. That value lives in a class variable, which non-main Ractors can't read on Ruby 4.0, so under Rails' experimental `Rails.application.ractorize!` every request failed.
|
|
16
|
+
|
|
17
|
+
*Mikael Henriksson*
|
|
18
|
+
|
|
19
|
+
* Fix `Component.translate` raising `UncaughtThrowError` for keys missing from the sidecar translations, and `NoMethodError` for components without sidecar translations. It now falls back to the global translations, like the instance method does. Fix `translate` returning the `default:` value instead of an existing global translation.
|
|
20
|
+
|
|
21
|
+
*Andrii Furmanets*
|
|
22
|
+
|
|
23
|
+
* Only recompile components when a template or a translation file changed, instead of before every request, when templates aren't cached. Pages render about twice as fast in development.
|
|
24
|
+
|
|
25
|
+
*Clément Joubert*
|
|
26
|
+
|
|
13
27
|
## 4.16.0
|
|
14
28
|
|
|
15
29
|
* Fix subclasses defined after their parent renders a collection using the parent's default collection parameter name instead of their own. Fix recompiling a component not refreshing its collection parameter, counter, and iteration detection. Compute that detection when a component compiles, and store the results frozen so they're shareable across Ractors.
|
|
@@ -25,5 +25,14 @@ module ViewComponent
|
|
|
25
25
|
def invalidate!
|
|
26
26
|
cache.clear
|
|
27
27
|
end
|
|
28
|
+
|
|
29
|
+
# Invalidates the cache when a template or a translation file is added,
|
|
30
|
+
# changed, or removed. Changes to Ruby files reload the application instead.
|
|
31
|
+
def template_watcher(file_watcher)
|
|
32
|
+
extensions = ActionView::Template::Handlers.extensions.map(&:to_s) + %w[yml yaml]
|
|
33
|
+
directories = ActiveSupport::Dependencies.autoload_paths.index_with(extensions)
|
|
34
|
+
|
|
35
|
+
file_watcher.new([], directories) { invalidate! }
|
|
36
|
+
end
|
|
28
37
|
end
|
|
29
38
|
end
|
|
@@ -132,9 +132,22 @@ module ViewComponent
|
|
|
132
132
|
end
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
# Like Rails' own template cache expiry, only watch templates when they
|
|
136
|
+
# aren't cached at boot. With template caching on, as in production, no
|
|
137
|
+
# hook runs per request, so requests never read ActionView's caching
|
|
138
|
+
# class variable, which non-main Ractors can't access.
|
|
139
|
+
ActiveSupport.on_load(:action_view) do
|
|
140
|
+
next if ActionView::Base.cache_template_loading
|
|
141
|
+
|
|
142
|
+
template_watcher = nil
|
|
143
|
+
|
|
144
|
+
app.executor.to_run :before do
|
|
145
|
+
template_watcher ||= CompileCache.template_watcher(app.config.file_watcher)
|
|
146
|
+
template_watcher.execute_if_updated
|
|
147
|
+
end
|
|
137
148
|
end
|
|
149
|
+
|
|
150
|
+
app.reloader.before_class_unload { CompileCache.invalidate! }
|
|
138
151
|
end
|
|
139
152
|
end
|
|
140
153
|
end
|
|
@@ -59,7 +59,11 @@ module ViewComponent
|
|
|
59
59
|
locale = options.delete(:locale) || ::I18n.locale
|
|
60
60
|
key = __vc_i18n_key(key, options.delete(:scope))
|
|
61
61
|
|
|
62
|
-
__vc_i18n_backend
|
|
62
|
+
if __vc_i18n_backend&.exists?(locale, key)
|
|
63
|
+
__vc_i18n_backend.translate(locale, key, options)
|
|
64
|
+
else
|
|
65
|
+
::I18n.translate(key, locale: locale, **options)
|
|
66
|
+
end
|
|
63
67
|
end
|
|
64
68
|
|
|
65
69
|
alias_method :t, :translate
|
|
@@ -102,17 +106,8 @@ module ViewComponent
|
|
|
102
106
|
|
|
103
107
|
__vc_html_escape_translation_options!(options) if as_html
|
|
104
108
|
|
|
105
|
-
if
|
|
106
|
-
translated =
|
|
107
|
-
catch(:exception) do
|
|
108
|
-
__vc_i18n_backend.translate(locale, key, options)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
# Fallback to the global translations
|
|
112
|
-
if translated.is_a? ::I18n::MissingTranslation
|
|
113
|
-
return @view_context.translate(key, locale: locale, **options)
|
|
114
|
-
end
|
|
115
|
-
|
|
109
|
+
if __vc_i18n_backend.exists?(locale, key)
|
|
110
|
+
translated = __vc_i18n_backend.translate(locale, key, options)
|
|
116
111
|
translated = __vc_html_safe_translation(translated) if as_html
|
|
117
112
|
translated
|
|
118
113
|
else
|