Skip to content

Commit

Permalink
:feat: Modify logic return for LRC when empty :closes: #6922
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal committed Sep 2, 2024
1 parent 88bfea5 commit 0ea0a6b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function __construct( $item ) {
/**
* Checks if the object has a valid LRC (Lazy Render Content) value.
*
* @return bool Returns true if the object's status is 'completed' and the Below the fold value is not empty or 'not found', false otherwise.
* @return bool Returns true if the object's status is 'completed' and the Below the fold value is not empty or '[]', false otherwise.
*/
public function has_lrc() {
if ( 'completed' !== $this->status ) {
Expand All @@ -103,7 +103,7 @@ public function has_lrc() {
return false;
}

if ( 'not found' === $this->below_the_fold ) {
if ( '[]' === $this->below_the_fold ) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ public function __construct( Processor $processor, ContextInterface $context ) {
* @return string
*/
public function optimize( string $html, $row ): string {
$html_without_hashes = $this->remove_hashes( $html );
if ( ! $row->has_lrc() ) {
return $html;
return $html_without_hashes;
}

$hashes = json_decode( $row->below_the_fold );

if ( null === $hashes || ! is_array( $hashes ) ) {
return $html;
return $html_without_hashes;
}

$result = preg_replace( '/data-rocket-location-hash="(?:' . implode( '|', $hashes ) . ')"/i', 'data-wpr-lazyrender="1"', $html, -1, $count );
Expand All @@ -59,7 +60,7 @@ public function optimize( string $html, $row ): string {
||
0 === $count
) {
return $html;
return $html_without_hashes;
}

$html = $result;
Expand Down

0 comments on commit 0ea0a6b

Please sign in to comment.