Skip to content

Commit

Permalink
Increase tag max length to 100
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Dec 2, 2024
1 parent e642c99 commit d2e90d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions plugins/image-prioritizer/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }`
Expand All @@ -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 ) {
Expand Down
7 changes: 5 additions & 2 deletions plugins/image-prioritizer/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://almanac.httparchive.org/en/2024/markup#fig-18>.
'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' ),
Expand Down

0 comments on commit d2e90d3

Please sign in to comment.