wp-media / wp-rocket

Performance optimization plugin for WordPress
https://wp-rocket.me
GNU General Public License v2.0
687 stars 215 forks source link

3.17: Beacon script isnot injected in the uncached page if URL have LRC and not have LCP #6890

Open Mai-Saad opened 3 weeks ago

Mai-Saad commented 3 weeks ago

Before submitting an issue please check that you’ve completed the following steps:

Describe the bug If URL have LRC and not LCP, the script is not injected when visiting the uncached page

To Reproduce Steps to reproduce the behavior:

  1. Visit a page => LCP and LRC added to DB
  2. Manually remove the LCP entry
  3. Clear cache
  4. visit the page

Expected behavior If one of the performance hints not exist in DB then script is injected to an uncached visit

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

Acceptance Criteria (for WP Media team use only) Clear instructions for developers, to be added before the grooming

MathieuLamiot commented 2 weeks ago

@jeawhanlee this issue has been moved to In Progress without grooming. I assume because it was possibly a quick fix in the first place? But it has been 4 days so maybe it is not and should get a grooming?

I don't know if this is linked but I was investigating something else and found this code: https://github.com/wp-media/wp-rocket/blob/fb50ef3b9db98b09b4b90797f5c16117a1560435/inc/Engine/Common/PerformanceHints/Frontend/Processor.php#L61-L78

$optimization_applied is badly handled and could be a problem for this issue:

The current code only accounts for the last factory of the loop because of this. Hence, if the last factory is LRC and LRC data exists, then $optimization_applied is set to true despite the fact that it was false after the LCP check.

The comment is misleading to. We should inject beacon if at least one optimization was not applied.