File tree Expand file tree Collapse file tree
lib/view_component/cache_digest Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ nav_order: 6
1010
1111## main
1212
13+ * Avoid ` NameError ` during eager loading when components include modules with temporary names.
14+
15+ * Joel Hawksley*
16+
1317* Avoid repeated scanning of unterminated ERB tags during cache dependency discovery.
1418
1519 * Joel Hawksley*
Original file line number Diff line number Diff line change @@ -145,7 +145,11 @@ def module_files(component)
145145 component . ancestors . take_while { |ancestor | ancestor != ViewComponent ::Base } . filter_map { |ancestor |
146146 next if ancestor . is_a? ( Class ) || ancestor . name . nil?
147147
148- path , _line = Object . const_source_location ( ancestor . name )
148+ begin
149+ path , _line = Object . const_source_location ( ancestor . name )
150+ rescue NameError
151+ next
152+ end
149153 path unless path . nil? || path . start_with? ( VIEW_COMPONENT_LIB )
150154 } . uniq
151155 end
Original file line number Diff line number Diff line change @@ -447,6 +447,21 @@ def test_cache_digest_changes_when_a_component_an_included_module_renders_change
447447 ) { CacheableHelperComponent . cache_digest }
448448 end
449449
450+ def test_modules_with_temporary_names_are_not_digested
451+ skip "Module#set_temporary_name requires Ruby 3.3+" unless Module . method_defined? ( :set_temporary_name )
452+
453+ component = CacheableHelperComponent . dup
454+ resolver = ViewComponent ::CacheDigest ::Resolver . instance
455+ source = resolver . source_for ( component )
456+ mod = Module . new
457+ component . include ( mod )
458+
459+ [ "ViewComponent::Properties(Extension)" , "MissingNamespace::Properties(Extension)" ] . each do |name |
460+ mod . set_temporary_name ( name )
461+ assert_equal source , resolver . source_for ( component )
462+ end
463+ end
464+
450465 # Every component includes modules from ViewComponent itself, which would
451466 # otherwise tie every digest to the installed version of the gem.
452467 def test_modules_view_component_includes_are_not_digested
You can’t perform that action at this time.
0 commit comments