view_component 4.2.0 → 4.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79d1337f1589a6e9ec7617c7d07917825c4f90b2e6093e6e925ef9fad3e06937
4
- data.tar.gz: aaa0ddcd3a30c628409a4001efdd99c702ff5b97ff7873a3f3e092e05b54c3f6
3
+ metadata.gz: 7cc3bb1d940451beebb05d7424ae9fe3124ddbfd2acc21e407c0b3c4964c7570
4
+ data.tar.gz: 2db13b63611d87477814e3567e2aca332879a50e1a500ecc560b8a9d0537c411
5
5
  SHA512:
6
- metadata.gz: 98381938a50a979a6ee135dff98c4e3b13a4a1b5ac8ee2f19c7e5f9b1bdc04470b355c55696d2724c733fab29a9379fe59c0a8e4273374e9db5210202be2dc06
7
- data.tar.gz: 0b5276ff41b7b7ff493f935c75e8c3e8cc604decc42a950c97f1da3becccfba3446b40178c35b9b54578a47f3718bfa53ba2c6e91ec7b929a6adc7f26f41f782
6
+ metadata.gz: 8dd9367ebb7c528a5a89d0a76d1294a0fa0276eed80b8c819d338c82d86c131386851903fb3fe0c1be43416980ebf9cb4ca405599f4e58f73084b1d5aee8fa8d
7
+ data.tar.gz: 4cca85cd44103692aed7039a7c0b044d78adbff6bbc0e5d99be0fe72590dae160047cf34ce731ec079141cf2ed22485d32898ce5917ec225e637951151c9d544
data/docs/CHANGELOG.md CHANGED
@@ -10,6 +10,24 @@ nav_order: 6
10
10
 
11
11
  ## main
12
12
 
13
+ ## 4.3.0
14
+
15
+ * Fix load order issues for 3rd-party template handlers.
16
+
17
+ *Cameron Dutro*
18
+
19
+ * Fix segfault when Ruby coverage is enabled with Rails 8.1 ERB templates.
20
+
21
+ *George Holborn*
22
+
23
+ * Automatically merge dependabot PRs.
24
+
25
+ *Joel Hawksley*
26
+
27
+ * Use Ruby 4.0.0 in CI and dev.
28
+
29
+ *Joel Hawksley*
30
+
13
31
  ## 4.2.0
14
32
 
15
33
  * Fix translation scope resolution in deeply nested component blocks (3+ levels). Translations called inside deeply nested slot blocks using `renders_many`/`renders_one` were incorrectly resolving to an intermediate component's scope instead of the partial's scope where the block was defined. The fix captures the virtual path at block definition time and restores it during block execution, ensuring translations always resolve relative to where the block was created regardless of nesting depth.
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "action_view"
4
+ require "action_view/base"
4
5
  require "view_component/collection"
5
6
  require "view_component/compile_cache"
6
7
  require "view_component/compiler"
@@ -577,7 +578,7 @@ module ViewComponent
577
578
  # eager loading is disabled and the parent component is rendered before the child. In
578
579
  # such a scenario, the parent will override ViewComponent::Base#render_template_for,
579
580
  # meaning it will not be called for any children and thus not compile their templates.
580
- if !child.instance_methods(false).include?(:render_template_for) && !child.__vc_compiled?
581
+ if !child.method_defined?(:render_template_for, false) && !child.__vc_compiled?
581
582
  child.class_eval <<~RUBY, __FILE__, __LINE__ + 1
582
583
  def render_template_for(requested_details)
583
584
  # Force compilation here so the compiler always redefines render_template_for.
@@ -600,7 +601,7 @@ module ViewComponent
600
601
  # Set collection parameter to the extended component
601
602
  child.with_collection_parameter(__vc_provided_collection_parameter)
602
603
 
603
- if instance_methods(false).include?(:render_template_for)
604
+ if method_defined?(:render_template_for, false)
604
605
  vc_ancestor_calls = defined?(@__vc_ancestor_calls) ? @__vc_ancestor_calls.dup : []
605
606
 
606
607
  vc_ancestor_calls.unshift(instance_method(:render_template_for))
@@ -115,11 +115,11 @@ module ViewComponent
115
115
  .tally
116
116
  .select { |_, count| count > 1 }
117
117
  .each do |tally|
118
- variant, this_format = tally.first
118
+ variant, this_format = tally.first
119
119
 
120
- variant_string = " for variant `#{variant}`" if variant.present?
120
+ variant_string = " for variant `#{variant}`" if variant.present?
121
121
 
122
- errors << "More than one #{this_format.upcase} template found#{variant_string} for #{@component}. "
122
+ errors << "More than one #{this_format.upcase} template found#{variant_string} for #{@component}. "
123
123
  end
124
124
 
125
125
  default_template_types = @templates.each_with_object(Set.new) do |template, memo|
@@ -190,11 +190,11 @@ module ViewComponent
190
190
  ).flat_map { |ancestor| ancestor.instance_methods(false).grep(/^call(_|$)/) }
191
191
  .uniq
192
192
  .each do |method_name|
193
- templates << Template::InlineCall.new(
194
- component: @component,
195
- method_name: method_name,
196
- defined_on_self: component_instance_methods_on_self.include?(method_name)
197
- )
193
+ templates << Template::InlineCall.new(
194
+ component: @component,
195
+ method_name: method_name,
196
+ defined_on_self: component_instance_methods_on_self.include?(method_name)
197
+ )
198
198
  end
199
199
 
200
200
  templates
@@ -259,7 +259,7 @@ module ViewComponent
259
259
 
260
260
  setter_method_name = :"with_#{poly_slot_name}"
261
261
 
262
- if instance_methods.include?(setter_method_name)
262
+ if method_defined?(setter_method_name)
263
263
  raise AlreadyDefinedPolymorphicSlotSetterError.new(setter_method_name, poly_slot_name)
264
264
  end
265
265
 
@@ -21,11 +21,21 @@ module ViewComponent
21
21
 
22
22
  class File < Template
23
23
  def initialize(component:, details:, path:)
24
- # Rails 8.1 added a newline to the compiled ERB output in
25
- # https://github.com/rails/rails/pull/53731
24
+ @strip_annotation_line = false
25
+
26
+ # Rails 8.1 added a newline to compiled ERB output (rails/rails#53731).
27
+ # Use -1 to compensate for correct line numbers in stack traces.
28
+ # However, negative line numbers cause segfaults when Ruby's coverage
29
+ # is enabled (bugs.ruby-lang.org/issues/19363). In that case, strip the
30
+ # annotation line from compiled source instead.
26
31
  lineno =
27
32
  if Rails::VERSION::MAJOR >= 8 && Rails::VERSION::MINOR > 0 && details.handler == :erb
28
- - 1
33
+ if coverage_running? && ActionView::Base.annotate_rendered_view_with_filenames
34
+ @strip_annotation_line = true
35
+ 0
36
+ else
37
+ -1
38
+ end
29
39
  else
30
40
  0
31
41
  end
@@ -46,6 +56,16 @@ module ViewComponent
46
56
  def source
47
57
  ::File.read(@path)
48
58
  end
59
+
60
+ private
61
+
62
+ def compiled_source
63
+ result = super
64
+ # Strip the annotation line to maintain correct line numbers when coverage
65
+ # is running (avoids segfault from negative lineno)
66
+ result = result.sub(/\A[^\n]*\n/, "") if @strip_annotation_line
67
+ result
68
+ end
49
69
  end
50
70
 
51
71
  class Inline < Template
@@ -54,8 +74,10 @@ module ViewComponent
54
74
  def initialize(component:, inline_template:)
55
75
  details = ActionView::TemplateDetails.new(nil, inline_template.language.to_sym, nil, nil)
56
76
 
57
- # Rails 8.1 added a newline to the compiled ERB output in
58
- # https://github.com/rails/rails/pull/53731
77
+ # Rails 8.1 added a newline to compiled ERB output (rails/rails#53731).
78
+ # Subtract 1 to compensate for correct line numbers in stack traces.
79
+ # Inline templates start at line 2+ (defined inside a class), so this
80
+ # won't result in negative line numbers that cause segfaults with coverage.
59
81
  lineno =
60
82
  if Rails::VERSION::MAJOR >= 8 && Rails::VERSION::MINOR > 0 && details.handler == :erb
61
83
  inline_template.lineno - 1
@@ -126,6 +148,10 @@ module ViewComponent
126
148
  @component.define_method(safe_method_name, @component.instance_method(@call_method_name))
127
149
  end
128
150
 
151
+ def coverage_running?
152
+ defined?(Coverage) && Coverage.running?
153
+ end
154
+
129
155
  def safe_method_name_call
130
156
  m = safe_method_name
131
157
  proc { send(m) }
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 4
6
- MINOR = 2
6
+ MINOR = 3
7
7
  PATCH = 0
8
8
  PRE = nil
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ViewComponent Team
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
- rubygems_version: 3.6.9
138
+ rubygems_version: 4.0.3
139
139
  specification_version: 4
140
140
  summary: A framework for building reusable, testable & encapsulated view components
141
141
  in Ruby on Rails.