Conversation
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the LCP candidate generation in BeaconLcp by filtering out elements that are not visually rendered (display: none, visibility: hidden, opacity: 0) and adds a comprehensive suite of tests to validate this behavior.
- Added style-based visibility checks in
_generateLcpCandidates. - Introduced extensive tests in
BeaconLcp.test.jscovering various visibility rules, edge cases, and the specific bug reproduction.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/BeaconLcp.js | Added window.getComputedStyle checks to exclude invisible elements. |
| test/BeaconLcp.test.js | Added tests for filtering by opacity, visibility, display, edge cases, and bug repro. |
wordpressfan
left a comment
There was a problem hiding this comment.
rocket-scripts/src/BeaconPreloadFonts.js
Lines 70 to 86 in 347894a
What do u think of making use of this method? we can move it into Utils class to be used when needed, what do u think?
|
@wordpressfan it's been updated |
Requested changes has been implemented.
Description
Fixes #7505
This fix resolves a bug in WP Rocket's LCP (Largest Contentful Paint) detection script where images with
opacity: 0,visibility: hidden, ordisplay: nonewere incorrectly being selected as LCP candidates.This caused WP Rocket to preload and optimize invisible images instead of the actual visible content that users see, negatively impacting performance optimization accuracy.
User Impact: WP Rocket now correctly identifies only visually rendered images as LCP candidates
Type of change
Detailed scenario
What was tested
Automated Tests:
opacity: 0are filtered out from LCP candidatesvisibility: hiddenare filtered out from LCP candidatesdisplay: noneare filtered out from LCP candidatesopacity: 1,visibility: visible,display: block) are includedManual Testing:
How to test
Use the provided template and run the beacon script, you'll see the hidden image is ignored in LCP candidates.
Technical description
Documentation
This pull request enhances the
BeaconLcpclass by improving the filtering logic for identifying visible elements and adds comprehensive test coverage for the changes. The most significant updates include the addition of visibility checks in the filtering logic and new tests to validate these changes.Enhancements to visibility filtering in
BeaconLcp:BeaconLcpto include a check for element visibility usingwindow.getComputedStyle. Elements withdisplay: none,visibility: hidden, oropacity: 0are now excluded from the LCP candidate list. (src/BeaconLcp.js, src/BeaconLcp.jsR57-R63)Comprehensive test coverage:
#_generateLcpCandidates(), inBeaconLcp.test.jsto validate the improved visibility filtering logic. Tests cover various scenarios, including:opacity: 0,visibility: hidden, ordisplay: nonebeing excluded.opacity: 0.01) and elements with zero dimensions.New dependencies
None
Risks
None
Mandatory Checklist
Code validation
Code style