@@ -1148,6 +1148,11 @@ def safe_display_config_value(label, config, method_name)
11481148 end
11491149 end
11501150
1151+ # Comment patterns used for filtering out commented async usage
1152+ ERB_COMMENT_PATTERN = /<%\s *#.*javascript_pack_tag/
1153+ HAML_COMMENT_PATTERN = /^\s *-#.*javascript_pack_tag/
1154+ HTML_COMMENT_PATTERN = /<!--.*javascript_pack_tag/
1155+
11511156 def check_async_usage
11521157 # When Pro is installed, async is fully supported and is the default behavior
11531158 # No need to check for async usage in this case
@@ -1186,7 +1191,7 @@ def scan_view_files_for_async_pack_tag
11861191 files_with_async . compact
11871192 rescue Errno ::ENOENT , Encoding ::InvalidByteSequenceError , Encoding ::UndefinedConversionError => e
11881193 # Log the error if Rails logger is available
1189- Rails . logger . debug ( "Error scanning view files for async: #{ e . message } " ) if defined? ( Rails ) && Rails . logger
1194+ log_debug ( "Error scanning view files for async: #{ e . message } " )
11901195 [ ]
11911196 end
11921197
@@ -1232,12 +1237,12 @@ def content_has_only_commented_async?(content)
12321237 # Skip lines that don't contain javascript_pack_tag
12331238 next unless line . include? ( "javascript_pack_tag" )
12341239
1235- # Skip ERB comments (<%# ... %>) - matches ERB comment opening with optional whitespace
1236- next if line . match? ( /<% \s *#.*javascript_pack_tag/ )
1237- # Skip HAML comments (-# ...) - matches line-starting HAML comments
1238- next if line . match? ( /^ \s *-#.*javascript_pack_tag/ )
1239- # Skip HTML comments (<!-- ... -->) - matches complete HTML comment blocks
1240- next if line . match? ( /<!--.*javascript_pack_tag/ )
1240+ # Skip ERB comments (<%# ... %>)
1241+ next if line . match? ( ERB_COMMENT_PATTERN )
1242+ # Skip HAML comments (-# ...)
1243+ next if line . match? ( HAML_COMMENT_PATTERN )
1244+ # Skip HTML comments (<!-- ... -->)
1245+ next if line . match? ( HTML_COMMENT_PATTERN )
12411246
12421247 # If we reach here, this line has an uncommented javascript_pack_tag
12431248 true
@@ -1263,9 +1268,15 @@ def config_has_async_loading_strategy?
12631268 end
12641269 rescue Errno ::ENOENT , Encoding ::InvalidByteSequenceError , Encoding ::UndefinedConversionError => e
12651270 # Log the error if Rails logger is available
1266- Rails . logger . debug ( "Error checking async loading strategy: #{ e . message } " ) if defined? ( Rails ) && Rails . logger
1271+ log_debug ( "Error checking async loading strategy: #{ e . message } " )
12671272 false
12681273 end
1274+
1275+ def log_debug ( message )
1276+ return unless defined? ( Rails . logger ) && Rails . logger
1277+
1278+ Rails . logger . debug ( message )
1279+ end
12691280 end
12701281 # rubocop:enable Metrics/ClassLength
12711282end
0 commit comments