view_component 2.74.0 → 2.75.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.

Potentially problematic release.


This version of view_component might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5727f1bca2f67cc366ef202592ccdcd6689be24204594f2bab68f25fed713034
4
- data.tar.gz: ef16e764d7a1403cf7480a44c93f8953a5cf943364d612146c71cde948dd7e72
3
+ metadata.gz: '0856bb7b57478e7604bb8f129a36448c937907308536649c59dc62a324fb8645'
4
+ data.tar.gz: 2211a54534c91373217a438c504d737054e538bb0f019d574eadd705b02b47ae
5
5
  SHA512:
6
- metadata.gz: 0bb378b5fc5181c5807a46af1cbdb8f51569d12b1d1b35791b41bdbc1b51ffea8b833bb86bbd37e442d5a1546e1dec9b2d8793728fb9fbd9f1ba427b9ebaa090
7
- data.tar.gz: cc6fc6362298a9ca1e6ec6d2e8fccd2b0ad06eb013cd710bdfb651245457c674ed0b0900c8407fa2f559e991c81ad9a53cdc4e48d630e739853b63b9621393c2
6
+ metadata.gz: 21585851a66d7a087e33a43a24c53284d5dd633703f636d202bf583f19d6c25b31830ebf47e7757ef38fa36ff981144ee16d4fe9d5dbc87eb7c2baddbddd039c
7
+ data.tar.gz: f16688c10f6c3fe6928573b199b2313436a8462e7fbb8d94b12aff9a36cde5cbbb090f8f9a2f3561c6dfa2b264192df746bc329bcb899905ca27046e60349d6e
data/docs/CHANGELOG.md CHANGED
@@ -10,6 +10,38 @@ nav_order: 5
10
10
 
11
11
  ## main
12
12
 
13
+ ## 2.75.0
14
+
15
+ * Avoid loading ActionView::Base during Rails initialization.
16
+
17
+ *Jonathan del Strother*
18
+
19
+ * Mention lambda slots rendering returned values lazily in the guide.
20
+
21
+ *Graham Rogers*
22
+
23
+ * Add "ViewComponent In The Wild" articles to resources.
24
+
25
+ *Alexander Baygeldin*
26
+
27
+ ## 2.74.1
28
+
29
+ * Add more users of ViewComponent to docs.
30
+
31
+ *Joel Hawksley*
32
+
33
+ * Add a known issue for usage with `turbo_frame_tag` to the documentation.
34
+
35
+ *Vlad Radulescu*
36
+
37
+ * Add note about system testing components with previews.
38
+
39
+ *Joel Hawksley*
40
+
41
+ * Remove locking mechanisms from the compiler.
42
+
43
+ *Cameron Dutro*
44
+
13
45
  ## 2.74.0
14
46
 
15
47
  * Add Avo to list of companies using ViewComponent.
@@ -28,6 +60,10 @@ nav_order: 5
28
60
 
29
61
  *Andy Baranov*
30
62
 
63
+ * `with_request_url` test helper supports router constraints (such as Devise).
64
+
65
+ *Aotokitsuruya*
66
+
31
67
  ## 2.73.0
32
68
 
33
69
  * Remove experimental `_after_compile` lifecycle method.
@@ -54,10 +90,6 @@ nav_order: 5
54
90
 
55
91
  *Anton Prins*
56
92
 
57
- * `with_request_url` test helper supports router constraints (such as Devise).
58
-
59
- *Aotokitsuruya*
60
-
61
93
  ## 2.72.0
62
94
 
63
95
  * Deprecate support for Ruby < 2.7 for removal in v3.0.0.
@@ -20,8 +20,9 @@ module ViewComponent
20
20
  delegate(*ViewComponent::Config.defaults.keys, to: :config)
21
21
 
22
22
  def config
23
- @config ||= ViewComponent::Config.defaults
23
+ @config ||= ActiveSupport::OrderedOptions.new
24
24
  end
25
+ attr_writer :config
25
26
  end
26
27
 
27
28
  include ViewComponent::ContentAreas
@@ -4,9 +4,6 @@ require "concurrent-ruby"
4
4
 
5
5
  module ViewComponent
6
6
  class Compiler
7
- # Lock required to be obtained before compiling the component
8
- attr_reader :__vc_compiler_lock
9
-
10
7
  # Compiler mode. Can be either:
11
8
  # * development (a blocking mode which ensures thread safety when redefining the `call` method for components,
12
9
  # default in Rails development and test mode)
@@ -18,7 +15,7 @@ module ViewComponent
18
15
 
19
16
  def initialize(component_class)
20
17
  @component_class = component_class
21
- @__vc_compiler_lock = Concurrent::ReadWriteLock.new
18
+ @redefinition_lock = Mutex.new
22
19
  end
23
20
 
24
21
  def compiled?
@@ -38,46 +35,40 @@ module ViewComponent
38
35
  end
39
36
 
40
37
  component_class.superclass.compile(raise_errors: raise_errors) if should_compile_superclass?
38
+ subclass_instance_methods = component_class.instance_methods(false)
41
39
 
42
- with_write_lock do
43
- CompileCache.invalidate_class!(component_class)
44
-
45
- subclass_instance_methods = component_class.instance_methods(false)
46
-
47
- if subclass_instance_methods.include?(:with_content) && raise_errors
48
- raise ViewComponent::ComponentError.new(
49
- "#{component_class} implements a reserved method, `#with_content`.\n\n" \
50
- "To fix this issue, change the name of the method."
51
- )
52
- end
53
-
54
- if template_errors.present?
55
- raise ViewComponent::TemplateError.new(template_errors) if raise_errors
40
+ if subclass_instance_methods.include?(:with_content) && raise_errors
41
+ raise ViewComponent::ComponentError.new(
42
+ "#{component_class} implements a reserved method, `#with_content`.\n\n" \
43
+ "To fix this issue, change the name of the method."
44
+ )
45
+ end
56
46
 
57
- return false
58
- end
47
+ if template_errors.present?
48
+ raise ViewComponent::TemplateError.new(template_errors) if raise_errors
59
49
 
60
- if subclass_instance_methods.include?(:before_render_check)
61
- ViewComponent::Deprecation.warn(
62
- "`#before_render_check` will be removed in v3.0.0.\n\n" \
63
- "To fix this issue, use `#before_render` instead."
64
- )
65
- end
50
+ return false
51
+ end
66
52
 
67
- if raise_errors
68
- component_class.validate_initialization_parameters!
69
- component_class.validate_collection_parameter!
70
- end
53
+ if subclass_instance_methods.include?(:before_render_check)
54
+ ViewComponent::Deprecation.warn(
55
+ "`#before_render_check` will be removed in v3.0.0.\n\n" \
56
+ "To fix this issue, use `#before_render` instead."
57
+ )
58
+ end
71
59
 
72
- templates.each do |template|
73
- # Remove existing compiled template methods,
74
- # as Ruby warns when redefining a method.
75
- method_name = call_method_name(template[:variant])
60
+ if raise_errors
61
+ component_class.validate_initialization_parameters!
62
+ component_class.validate_collection_parameter!
63
+ end
76
64
 
77
- if component_class.instance_methods.include?(method_name.to_sym)
78
- component_class.send(:undef_method, method_name.to_sym)
79
- end
65
+ templates.each do |template|
66
+ # Remove existing compiled template methods,
67
+ # as Ruby warns when redefining a method.
68
+ method_name = call_method_name(template[:variant])
80
69
 
70
+ redefinition_lock.synchronize do
71
+ component_class.silence_redefinition_of_method(method_name)
81
72
  # rubocop:disable Style/EvalWithLocation
82
73
  component_class.class_eval <<-RUBY, template[:path], 0
83
74
  def #{method_name}
@@ -86,36 +77,20 @@ module ViewComponent
86
77
  RUBY
87
78
  # rubocop:enable Style/EvalWithLocation
88
79
  end
89
-
90
- define_render_template_for
91
-
92
- component_class.build_i18n_backend
93
-
94
- CompileCache.register(component_class)
95
80
  end
96
- end
97
81
 
98
- def with_write_lock(&block)
99
- if development?
100
- __vc_compiler_lock.with_write_lock(&block)
101
- else
102
- block.call
103
- end
104
- end
82
+ define_render_template_for
83
+
84
+ component_class.build_i18n_backend
105
85
 
106
- def with_read_lock(&block)
107
- __vc_compiler_lock.with_read_lock(&block)
86
+ CompileCache.register(component_class)
108
87
  end
109
88
 
110
89
  private
111
90
 
112
- attr_reader :component_class
91
+ attr_reader :component_class, :redefinition_lock
113
92
 
114
93
  def define_render_template_for
115
- if component_class.instance_methods.include?(:render_template_for)
116
- component_class.send(:undef_method, :render_template_for)
117
- end
118
-
119
94
  variant_elsifs = variants.compact.uniq.map do |variant|
120
95
  "elsif variant.to_sym == :#{variant}\n #{call_method_name(variant)}"
121
96
  end.join("\n")
@@ -129,15 +104,8 @@ module ViewComponent
129
104
  end
130
105
  RUBY
131
106
 
132
- if development?
133
- component_class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
134
- def render_template_for(variant = nil)
135
- self.class.compiler.with_read_lock do
136
- #{body}
137
- end
138
- end
139
- RUBY
140
- else
107
+ redefinition_lock.synchronize do
108
+ component_class.silence_redefinition_of_method(:render_template_for)
141
109
  component_class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
142
110
  def render_template_for(variant = nil)
143
111
  #{body}
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rails"
4
- require "view_component/base"
4
+ require "view_component/config"
5
5
 
6
6
  module ViewComponent
7
7
  class Engine < Rails::Engine # :nodoc:
8
- config.view_component = ViewComponent::Base.config
8
+ config.view_component = ViewComponent::Config.defaults
9
9
 
10
10
  rake_tasks do
11
11
  load "view_component/rails/tasks/view_component.rake"
@@ -14,9 +14,6 @@ module ViewComponent
14
14
  initializer "view_component.set_configs" do |app|
15
15
  options = app.config.view_component
16
16
 
17
- %i[generate preview_controller preview_route show_previews_source].each do |config_option|
18
- options[config_option] ||= ViewComponent::Base.public_send(config_option)
19
- end
20
17
  options.instrumentation_enabled = false if options.instrumentation_enabled.nil?
21
18
  options.render_monkey_patch_enabled = true if options.render_monkey_patch_enabled.nil?
22
19
  options.show_previews = (Rails.env.development? || Rails.env.test?) if options.show_previews.nil?
@@ -39,6 +36,8 @@ module ViewComponent
39
36
 
40
37
  initializer "view_component.enable_instrumentation" do |app|
41
38
  ActiveSupport.on_load(:view_component) do
39
+ Base.config = app.config.view_component
40
+
42
41
  if app.config.view_component.instrumentation_enabled.present?
43
42
  # :nocov:
44
43
  ViewComponent::Base.prepend(ViewComponent::Instrumentation)
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 74
6
+ MINOR = 75
7
7
  PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.74.0
4
+ version: 2.75.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ViewComponent Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-28 00:00:00.000000000 Z
11
+ date: 2022-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport