Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #6638: Handle Properly picture tag #6659

Merged
merged 26 commits into from
Jun 10, 2024

Conversation

Miraeld
Copy link
Contributor

@Miraeld Miraeld commented May 24, 2024

Description

Fixes #6638 #6660 #6669

Documentation

User documentation

First of all, this PR brings a fix for the LCP candidates when it's a <picture> tag detected. Before, we would also detect the sub-tag <img> and both would compete each other leading to errors.
Then, it also brings another way to process <picture> tag when there is a type attribute in order to preload the first <source> image.

Technical documentation

Type of change

  • Enhancement (non-breaking change which improves an existing functionality).

New dependencies

Risks

Checklists

Feature validation

  • I validated all the Acceptance Criteria. If possible, provide sreenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Documentation

  • I prepared the user documentation for the feature/enhancement and shared it in the PR or the GitHub issue.
  • The user documentation covers new/changed entry points (endpoints, WP hooks, configuration files, ...).
  • I prepared the technical documentation if needed, and shared it in the PR or the GitHub issue.

Code style

  • I wrote self-explanatory code about what it does.
  • I wrote comments to explain why it does it.
  • I named variables and functions explicitely.
  • I protected entry points against unexpected inputs.
  • I did not introduce unecessary complexity.
  • I listed the introduced external dependencies explicitely on the PR.
  • I validated the repo-specific guidelines from CONTRIBUTING.md.

Observability

  • I handled errors when needed.
  •  I wrote user-facing messages that are understandable and provide actionable feedbacks.
  • I prepared ways to observe the implemented system (logs, data, etc.).

Risks

  •  I explicitely mentioned performance risks in the PR.
  • I explicitely mentioned security risks in the PR.

@Miraeld Miraeld added the type: enhancement Improvements that slightly enhance existing functionality and are fast to implement label May 24, 2024
@Miraeld Miraeld added this to the 3.16.1 milestone May 24, 2024
@Miraeld Miraeld requested a review from a team May 24, 2024 11:51
@Miraeld Miraeld self-assigned this May 24, 2024
@Miraeld Miraeld force-pushed the enhancement/6638-handle-picture-tag-in-lcp-preload branch from 2d0f5d6 to 3a16cb0 Compare May 24, 2024 12:01
Copy link

codacy-production bot commented May 24, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 39b8f181 100.00% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (39b8f18) Report Missing Report Missing Report Missing
Head commit (bab312a) 37228 14421 38.74%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#6659) 8 8 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy will stop sending the deprecated coverage status from June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@Miraeld Miraeld force-pushed the enhancement/6638-handle-picture-tag-in-lcp-preload branch from 5efbb83 to d80f88e Compare May 27, 2024 21:11
Fix the empty href & duplicated `min-width` with picture tag
@Tabrisrp
Copy link
Contributor

Need to lint the code a bit

@Miraeld
Copy link
Contributor Author

Miraeld commented May 28, 2024

My bad, didn't see that failed CI.
Done :)

@Mai-Saad
Copy link

Mai-Saad commented May 29, 2024

@Miraeld
Copy link
Contributor Author

Miraeld commented May 31, 2024

Good morning @Mai-Saad & @piotrbak ,

Latest commits are adding the following:

Also, e2e is passing on my side, everything ok.

@MathieuLamiot MathieuLamiot requested a review from a team June 5, 2024 14:47
@MathieuLamiot
Copy link
Contributor

@Miraeld I see you moved this to Ready for Review.
But it is not up-to-date with develop and there are no E2E results shared for this PR updated on develop. Can you make sure to provide all this?

@Miraeld
Copy link
Contributor Author

Miraeld commented Jun 5, 2024

The codebase is ready for review,
I'm trying to run e2e, but can't get it working (the whole e2e app), non related to this PR.

And it's just been updated with develop latest changes.

@Mai-Saad
Copy link

Mai-Saad commented Jun 6, 2024

@wordpressfan Thanks for sharing markups above.

  • For the 1st markup

	<picture class="core-image">
		<source type="image/webp" media='(max-width: 500px)' srcset="https://variance.pl/wp-content/uploads/2024/05/Kwiatowy-Ksiezyc-400x600.webp">
		<source type="image/webp" media='(min-width: 501px) and (max-width: 768px)' srcset="https://variance.pl/wp-content/uploads/2024/05/Kwiatowy-Ksiezyc-768x513.webp">
		<img class="skip-lazy" src="https://variance.pl/wp-content/uploads/2024/05/Kwiatowy-Ksiezyc-1348x900.webp" alt="Kwiatowy księżyc" title="Kwiatowy księżyc">
	</picture>

Update: it's 2nd source missing and thus min-width is not correct thanks to @Miraeld

it's missing to preload <img> + and max-width of 2nd image => clear on this page https://new.rocketlabsqa.ovh/lcp_picture_media_type_mixed/. @wp-media/productrocket it contains both min-width and max-width, please confirm expected here. (now no empty href nor duplicated min-width but we didn't preload img tag and we removed and max-width from 2nd image)
Expected markup as per original issue #6669:

<link rel="preload" as="image" href="https://variance.pl/wp-content/uploads/2024/05/Kwiatowy-Ksiezyc-400x600.webp" media="(max-width: 500px)" fetchpriority="high">
<link rel="preload" as="image" href="https://variance.pl/wp-content/uploads/2024/05/Kwiatowy-Ksiezyc-768x513.webp" media="(min-width: 501px) and (max-width: 768px)" fetchpriority="high">
<link rel="preload" as="image" href="https://variance.pl/wp-content/uploads/2024/05/Kwiatowy-Ksiezyc-1348x900.webp" alt="Kwiatowy księżyc" media="(min-width: 768.1px)" fetchpriority="high">

@MathieuLamiot
Copy link
Contributor

E2E results: https://wp-media.slack.com/archives/CUT7FLHF1/p1717653110913929?thread_ts=1717624428.972699&cid=CUT7FLHF1
Moving this to Ready for Review. And pending Product feedback.

@Miraeld
Copy link
Contributor Author

Miraeld commented Jun 6, 2024

I was checking on develop,
while using the HTML markup:

	<picture class="core-image">
		<source type="image/webp" media='(max-width: 500px)' srcset="https://variance.pl/wp-content/uploads/2024/05/Kwiatowy-Ksiezyc-400x600.webp">
		<source type="image/webp" media='(min-width: 501px) and (max-width: 768px)' srcset="https://variance.pl/wp-content/uploads/2024/05/Kwiatowy-Ksiezyc-768x513.webp">
		<img class="skip-lazy" src="https://variance.pl/wp-content/uploads/2024/05/Kwiatowy-Ksiezyc-1348x900.webp" alt="Kwiatowy księżyc" title="Kwiatowy księżyc">
	</picture>

@piotrbak for everything related to the only markup @Mai-Saad mentioned was wrong, on develop we are getting the following preload tag:

<link rel="preload" as="image" href="https://variance.pl/wp-content/uploads/2024/05/Kwiatowy-Ksiezyc-1348x900.webp" fetchpriority="high">

What we are getting on this PR:

<link rel="preload" as="image" href="https://variance.pl/wp-content/uploads/2024/05/Kwiatowy-Ksiezyc-400x600.webp" media="(max-width: 500px)" fetchpriority="high">
<link rel="preload" as="image" href="https://variance.pl/wp-content/uploads/2024/05/Kwiatowy-Ksiezyc-1348x900.webp" media="(min-width: 500.1px)" fetchpriority="high">

Not sure if this is a regression or not what we are getting with this PR.
What is the actual expected behavior for this ? Is @Mai-Saad correct in her latest comment :

<link rel="preload" as="image" href="https://variance.pl/wp-content/uploads/2024/05/Kwiatowy-Ksiezyc-400x600.webp" media="(max-width: 500px)" fetchpriority="high">
<link rel="preload" as="image" href="https://variance.pl/wp-content/uploads/2024/05/Kwiatowy-Ksiezyc-768x513.webp" media="(min-width: 501px) and (max-width: 768px)" fetchpriority="high">
<link rel="preload" as="image" href="https://variance.pl/wp-content/uploads/2024/05/Kwiatowy-Ksiezyc-1348x900.webp" alt="Kwiatowy księżyc" media="(min-width: 768.1px)" fetchpriority="high">

I was thinking to move this case out of this PR, so everything else can move forward while this one is being worked on.
What do you think ?

EDIT:
After looking into it a bit, it isn't the <img tag that isn't preloaded, but the second <source> tag.
This is due to this bail-out here, which was introduce to tackle another case of the picture tag.

Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 4dd69dd1 100.00% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (4dd69dd) Report Missing Report Missing Report Missing
Head commit (89f3948) 37263 14459 38.80%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#6659) 14 14 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@Miraeld
Copy link
Contributor Author

Miraeld commented Jun 6, 2024

@Mai-Saad ,
As per discussion here, we can move forward with this PR, while fixing the remaining markup in another issue here

@Miraeld
Copy link
Contributor Author

Miraeld commented Jun 7, 2024

@MathieuLamiot , @Mai-Saad ,
This PR Now includes changes from #6708, & #6709.
Which means the picture tag should work properly now, on every aspect + the src regression is fixed.

@Miraeld Miraeld linked an issue Jun 7, 2024 that may be closed by this pull request
@Mai-Saad
Copy link

Mai-Saad commented Jun 8, 2024

@Miraeld Thanks for the update.
Tested templates:

Possible breaking markups (not sure if it's common, needs further investigation and expected o/p from @wp-media/productrocket if we will handle any in new GH maybe):

  1. test page https://new.rocketlabsqa.ovh/lcp_picture_responsive_type_mixed/
     <picture   class="wp-image-8418">
   <source Type="image/avif" Media = '(max-width: 500px)' Srcset="https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-1024x576.jpg.avif 1024w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-300x169.jpg.avif 300w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-768x432.jpg.avif 768w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-1536x864.jpg.avif 1536w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-1200x675.jpg.avif 1200w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-600x338.jpg.avif 600w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia.jpg.avif 1920w" sizes="(max-width: 1024px) 100vw, 1024px">
   <source type = "image/webp" Media='(max-width: 800px)' SRCSET="https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-1024x576.jpg.webp 1024w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-300x169.jpg.webp 300w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-768x432.jpg.webp 768w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-1536x864.jpg.webp 1536w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-1200x675.jpg.webp 1200w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-600x338.jpg.webp 600w" sizes="(max-width: 1024px) 100vw, 1024px">
   <img  width="1024" height="576" Src="https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-1024x576.jpg" alt="" srcset="https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-1024x576.jpg 1024w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-300x169.jpg 300w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-768x432.jpg 768w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-1536x864.jpg 1536w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-1200x675.jpg 1200w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia-600x338.jpg 600w, https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-—-kopia.jpg 1920w" sizes="(max-width: 1024px) 100vw, 1024px">
</picture>

will be preloaded as

<link rel="preload" as="image" href="https://imagify.rocketlabsqa.ovh/wp-content/uploads/2024/05/home-new-bg-free-img-%E2%80%94-kopia-1024x576.jpg" media="(min-width: 500.1px)" fetchpriority="high">

2- using max-height instead of max-width https://new.rocketlabsqa.ovh/lcp_picture_template2_maxheight/

<picture class="picture_test2"> 
			<source srcset="<?php echo content_url().'/rocket-test-data/images/paper.jpeg' ?>" media="(max-height: 400px)"> 
			<source  srcset="<?php echo content_url().'/rocket-test-data/images/lcp/testjpeg.jpeg' ?>" media="(max-height: 800px)"> 
			<img src="<?php echo content_url().'/rocket-test-data/images/lcp/testwebp.webp'?>"> 	
		</picture>

will be

<link rel="preload" as="image" href="https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/images/paper.jpeg" media="(max-height: 400px)" fetchpriority="high">
<link rel="preload" as="image" href="https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/images/lcp/testjpeg.jpeg" media="(max-height: 800px)" fetchpriority="high">

@MathieuLamiot
Copy link
Contributor

Re-ran E2E to confirm: all good (details here).

Only waiting for @piotrbak @DahmaniAdame confirmation on the 2 points from @Mai-Saad above.

@piotrbak
Copy link
Contributor

@MathieuLamiot @Mai-Saad We're good with those

@Khadreal Khadreal added this pull request to the merge queue Jun 10, 2024
Merged via the queue into develop with commit c450ed1 Jun 10, 2024
23 checks passed
@Khadreal Khadreal deleted the enhancement/6638-handle-picture-tag-in-lcp-preload branch June 10, 2024 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Improvements that slightly enhance existing functionality and are fast to implement
Projects
None yet
8 participants