Skip to content

Commit

Permalink
Merge branch 'develop' into enhancement/6879-meta-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
remyperona committed Oct 17, 2024
2 parents c8b3d2b + 3c774bb commit 513c688
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 14 deletions.
39 changes: 39 additions & 0 deletions assets/js/wpr-beacon.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,40 @@
}
return false;
}
_checkLcrConflict(element) {
const conflictingElements = [];
const computedStyle = window.getComputedStyle(element);
const validMargins = ["marginTop", "marginRight", "marginBottom", "marginLeft"];
const negativeMargins = validMargins.some((margin) => parseFloat(computedStyle[margin]) < 0);
const currentElementConflicts = negativeMargins || computedStyle.contentVisibility === "auto" || computedStyle.contentVisibility === "hidden";
if (currentElementConflicts) {
conflictingElements.push({
element,
conflicts: [
negativeMargins && "negative margin",
computedStyle.contentVisibility === "auto" && "content-visibility:auto",
computedStyle.contentVisibility === "hidden" && "content-visibility:hidden"
].filter(Boolean)
});
}
Array.from(element.children).forEach((child) => {
const childStyle = window.getComputedStyle(child);
const validMargins2 = ["marginTop", "marginRight", "marginBottom", "marginLeft"];
const childNegativeMargins = validMargins2.some((margin) => parseFloat(childStyle[margin]) < 0);
const childConflicts = childNegativeMargins || childStyle.position === "absolute" || childStyle.position === "fixed";
if (childConflicts) {
conflictingElements.push({
element: child,
conflicts: [
childNegativeMargins && "negative margin",
childStyle.position === "absolute" && "position:absolute",
childStyle.position === "fixed" && "position:fixed"
].filter(Boolean)
});
}
});
return conflictingElements;
}
_processElements(elements) {
elements.forEach(({ element, depth, distance, hash }) => {
if (this._shouldSkipElement(element, this.config.exclusions || [])) {
Expand All @@ -265,6 +299,11 @@
if ("No hash detected" === hash) {
return;
}
const conflicts = this._checkLcrConflict(element);
if (conflicts.length > 0) {
this.logger.logMessage("Skipping element due to conflicts:", conflicts);
return;
}
const can_push_hash = element.parentElement && this._getElementDistance(element.parentElement) < this.config.lrc_threshold && distance >= this.config.lrc_threshold;
const color = can_push_hash ? "green" : distance === 0 ? "red" : "";
this.logger.logColoredMessage(`${" ".repeat(depth)}${element.tagName} (Depth: ${depth}, Distance from viewport bottom: ${distance}px)`, color);
Expand Down
2 changes: 1 addition & 1 deletion assets/js/wpr-beacon.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions assets/js/wpr-beacon.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dynamic-lists-delayjs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dynamic-lists.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inc/Engine/Admin/Database/OptimizationProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected function task( $item ) {
}
break;
case 'database_optimize_tables':
$query = $wpdb->get_results( "SELECT table_name, data_free FROM information_schema.tables WHERE table_schema = '" . DB_NAME . "' and Engine <> 'InnoDB' and data_free > 0" );
$query = $wpdb->get_results( "SELECT table_name AS table_name, data_free AS data_free FROM information_schema.tables WHERE table_schema = '" . DB_NAME . "' and Engine <> 'InnoDB' and data_free > 0" );
if ( $query ) {
$number = 0;
foreach ( $query as $table ) {
Expand Down
4 changes: 2 additions & 2 deletions inc/Engine/CDN/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function __construct( Options_Data $options, CDN $cdn ) {
public static function get_subscribed_events() {
return [
'rocket_buffer' => [
[ 'rewrite', 20 ],
[ 'rewrite_srcset', 21 ],
[ 'rewrite', 2 ],
[ 'rewrite_srcset', 3 ],
],
'rocket_css_content' => 'rewrite_css_properties',
'rocket_usedcss_content' => 'rewrite_css_properties',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public function delete_by_url( string $url ) {

$deleted = true;
foreach ( $items as $item ) {
if ( ! is_object( $item ) || ! isset( $item->id ) ) {
continue;
}

$deleted = $deleted && $this->delete_item( $item->id );
}

Expand Down
4 changes: 4 additions & 0 deletions inc/Engine/Common/PerformanceHints/Frontend/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public function maybe_apply_optimizations( string $html ): string {
* @return string The modified HTML content with the beacon script injected just before the closing body tag.
*/
private function inject_beacon( $html, $url, $is_mobile ): string {
if ( rocket_get_constant( 'DONOTROCKETOPTIMIZE' ) ) {
return $html;
}

$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';

if ( ! $this->filesystem->exists( rocket_get_constant( 'WP_ROCKET_ASSETS_JS_PATH' ) . 'wpr-beacon' . $min . '.js' ) ) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"watchify": "^4.0.0",
"webpack": "^5.76.0",
"webpack-cli": "^4.9.1",
"wp-rocket-scripts": "^1.0.6",
"wp-rocket-scripts": "^1.0.7",
"yargs": "^17.3.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
$result_one = (object) [
'id' => 1
];

$result_two = (object) [
'id' => 2
];

$empty_result_one = (object) [
];

return [
'notResultsShouldNotDelete' => [
'config' => [
'url' => 'http://example.com',
'results' => [],
'deleted_item' => 0
],
'expected' => false,
],
'resultsWithEmptyObjectShouldReturnFalse' => [
'config' => [
'url' => 'http://example.com',
'deleted_item' => 1,
'results' => [
$empty_result_one,
$result_two,
],
'delete_id_one' => true,
'delete_id_two' => 2,
'delete_return_one' => true,
'delete_return_two' => true,
],
'expected' => true,
],
'resultsWithOneErrorShouldReturnFalse' => [
'config' => [
'url' => 'http://example.com',
'deleted_item' => 2,
'results' => [
$result_one,
$result_two,
],
'delete_id_one' => 1,
'delete_id_two' => 2,
'delete_return_one' => true,
'delete_return_two' => true,
],
'expected' => true,
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@
],
'expected' => $html_input,
],
'shouldReturnOriginalWhenDonotoptimize' => [
'config' => [
'donotrocketoptimize' => true,
'html' => $html_input,
'atf' => [
'row' => null,
],
'lrc' => [
'row' => null,
],
],
'expected' => $html_input,
],
'shouldAddBeaconToPage' => [
'config' => [
'html' => $html_input,
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/inc/Engine/CDN/Subscriber/rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function set_up() {

add_filter( 'rocket_disable_meta_generator', '__return_true' );

$this->unregisterAllCallbacksExcept( 'rocket_buffer', 'rewrite', 20 );
$this->unregisterAllCallbacksExcept( 'rocket_buffer', 'rewrite', 2 );
}

public function tear_down() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function tear_down() {
public function testShouldReturnAsExpected( $config, $expected ) {
$this->config = $config;
$this->cached_user = $config['user_cache_enabled'] ?? false;
$this->donotrocketoptimize = $config['donotrocketoptimize'] ?? null;

if ( isset( $config['query_string'] ) ) {
$_GET[ $config['query_string'] ] = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Engine\Common\PerformanceHints\Database;

use WP_Rocket\Tests\Unit\TestCase;
use WP_Rocket\Engine\Common\PerformanceHints\Database\Queries\AbstractQueries;
/**
* Test class covering WP_Rocket\Engine\Common\PerformanceHints\Database\Queries\AbstractQueries::delete_by_url
*
* @group PerformanceHints
*/
class Test_DeleteByUrl extends TestCase
{
protected $query;

protected function setUp(): void
{
parent::setUp();
$this->query = $this->createPartialMock( AbstractQueries::class, [ 'table_exists', 'get_rows_by_url', 'delete_item' ] );
}

/**
* @dataProvider configTestData
*/
public function testShouldReturnAsExpected($config, $expected) {
$this->query->expects($this->once())
->method('table_exists')
->willReturn(true);

$this->query->expects(self::once())->method('get_rows_by_url')->with($config['url'])->willReturn($config['results']);
$this->configureDelete($config, $expected);

$this->assertSame($expected, $this->query->delete_by_url($config['url']));
}

protected function configureDelete($config, $expected) {
if(count($config['results']) === 0) {
return;
}
if ( ! $expected ) {
return;
}

$this->query->expects(self::exactly($config['deleted_item']))->method('delete_item')
->withConsecutive([$config['delete_id_one']], [$config['delete_id_two']])
->willReturnOnConsecutiveCalls($config['delete_return_one'], $config['delete_return_two']);
}
}
6 changes: 3 additions & 3 deletions wp-rocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WP Rocket
* Plugin URI: https://wp-rocket.me
* Description: The best WordPress performance plugin.
* Version: 3.17.0.2
* Version: 3.17.1
* Requires at least: 5.8
* Requires PHP: 7.3
* Code Name: Iego
Expand All @@ -14,13 +14,13 @@
* Text Domain: rocket
* Domain Path: languages
*
* Copyright 2013-2023 WP Rocket
* Copyright 2013-2024 WP Rocket
*/

defined( 'ABSPATH' ) || exit;

// Rocket defines.
define( 'WP_ROCKET_VERSION', '3.17.0.2' );
define( 'WP_ROCKET_VERSION', '3.17.1' );
define( 'WP_ROCKET_WP_VERSION', '5.8' );
define( 'WP_ROCKET_WP_VERSION_TESTED', '6.3.1' );
define( 'WP_ROCKET_PHP_VERSION', '7.3' );
Expand Down

0 comments on commit 513c688

Please sign in to comment.