From d2e90d36e448bdb2ff325fbdcf2af832febf78fa Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 2 Dec 2024 09:53:57 -0800 Subject: [PATCH] Increase tag max length to 100 --- plugins/image-prioritizer/detect.js | 5 +++-- plugins/image-prioritizer/helper.php | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/image-prioritizer/detect.js b/plugins/image-prioritizer/detect.js index e04a81d0d..acc72d8a7 100644 --- a/plugins/image-prioritizer/detect.js +++ b/plugins/image-prioritizer/detect.js @@ -153,8 +153,8 @@ function handleLCPMetric( metric, isDebug ) { return; } - // Also skip Custom Elements which have excessively long tag names. - if ( entry.element.tagName.length > 25 ) { + // Also skip Custom Elements which have excessively long tag names. This is the maxLength defined in image_prioritizer_add_element_item_schema_properties(). + if ( entry.element.tagName.length > 100 ) { if ( isDebug ) { log( `Skipping very long tag name: ${ entry.element.tagName }` @@ -164,6 +164,7 @@ function handleLCPMetric( metric, isDebug ) { } // Note that getAttribute() is used instead of properties so that null can be returned in case of an absent attribute. + // The maxLengths are defined in image_prioritizer_add_element_item_schema_properties(). const id = entry.element.getAttribute( 'id' ); if ( typeof id === 'string' && id.length > 100 ) { if ( isDebug ) { diff --git a/plugins/image-prioritizer/helper.php b/plugins/image-prioritizer/helper.php index 5667a97d2..6b9a6d423 100644 --- a/plugins/image-prioritizer/helper.php +++ b/plugins/image-prioritizer/helper.php @@ -135,8 +135,11 @@ function image_prioritizer_add_element_item_schema_properties( array $additional 'type' => 'string', 'required' => true, 'minLength' => 1, - 'maxLength' => 25, // The longest HTML tag name is 10 characters (BLOCKQUOTE and FIGCAPTION). This maxLength accounts for possible Custom Elements that are even longer. - 'pattern' => '^[a-zA-Z0-9\-]+$', // Technically emoji can be allowed in a custom element's tag name, but this is not supported here. + // The longest HTML tag name is 10 characters (BLOCKQUOTE and FIGCAPTION), but SVG tag names can be longer + // (e.g. feComponentTransfer). This maxLength accounts for possible Custom Elements that are even longer, + // although the longest known Custom Element from HTTP Archive is 32 characters. See data from . + 'maxLength' => 100, + 'pattern' => '^[a-zA-Z0-9\-]+\z', // Technically emoji can be allowed in a custom element's tag name, but this is not supported here. ), 'id' => array( 'type' => array( 'string', 'null' ),