Code Monkey home page Code Monkey logo

Comments (2)

MathieuLamiot avatar MathieuLamiot commented on July 24, 2024

Bringing back to ToDo as this is not fixed: I still have errors when re-visiting the page and the LCP value in case of not found is not "not found" but null.
There are several issues:

  1. the beacon script sends an "image" with lcp label, even if there is no element.
    To fix this, I modified "topCandidates" in the beacon by adding a filter to take out items where the getElementInfo did not find anything relevant:
	const topCandidates = potentialCandidates.map(element => {
		const rect = element.getBoundingClientRect();
		return {
			element: element,
			rect: rect,
		};
	}).filter(item => {
		return (
			item.rect.width > 0 &&
			item.rect.height > 0 &&
			isIntersecting(item.rect)
		);
	})
	.map(item => ({
		item,
		area: getArea(item.rect),
		elementInfo: getElementInfo(item.element),
	}))
	.filter(item => {
		return (
			item.elementInfo !== null && 
			item.elementInfo.type !== ""
		);
	})
	.sort((a, b) => b.area - a.area)
	.slice(0, count);

The issue is that, even if getElementInfo does not find anything, it returns an elementInfo with a dummy structure. Hence, the check later on const firstElementWithInfo = above_the_fold_images.find(item => item.elementInfo !== null); seems useless! There will always be a elementInfo ; but a dummy one sometimes.
It might not be the right way to do it, but the 1st issue is here: notice that without this fix, we don't have the log "No LCP element found" on http://mathieu.e2e.rocketlabsqa.ovh/ for instance. This shows that the beacon thinks there is an LCP becasue it does not filter out empty/irrelevant elements.

  1. Once this is fixed, instead of null in the DB, I get "not found". Be careful, the " are actually in the string! This leads to the following warning logs:
[25-Apr-2024 16:53:58 UTC] PHP Warning:  Attempt to read property "type" on string in /var/www/html/mathieu.e2e.rocketlabsqa.ovh/wp-content/plugins/wp-rocket/inc/Engine/Media/AboveTheFold/Frontend/Controller.php on line 250
[25-Apr-2024 16:53:58 UTC] PHP Warning:  Attempt to read property "type" on string in /var/www/html/mathieu.e2e.rocketlabsqa.ovh/wp-content/plugins/wp-rocket/inc/Engine/Media/AboveTheFold/Frontend/Controller.php on line 143

The issue is: the check in has_lcp $lcp !== 'not found' is true because '"not found"' !== 'not found'
I think the additional " comes from the use of wp_json_encode in 'lcp' => wp_json_encode( $lcp ),
two choices here: either change how we write into the DB in case $lcp = 'not found' to avoid adding the additional ", or change the has_lcp check.

After this, it seems working as expected, without logs.

One should check this, fix and ensure the modifications don't break tests on Rocket-E2E.

from wp-rocket.

Mai-Saad avatar Mai-Saad commented on July 24, 2024

Note: other page template without images on e2e https://e2e.rocketlabsqa.ovh/lcp_no_images/

from wp-rocket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.