-
Notifications
You must be signed in to change notification settings - Fork 140
Don't wrap PICTURE element if JPEG fallback is not available #1450
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
Don't wrap PICTURE element if JPEG fallback is not available #1450
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @sagarnasit. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Just a couple tweaks, and then it seems the only thing left is to add a test.
|
@westonruter I updated the check for Additionally, I've included a separate test file for the fallback image as the "Output JPEG" setting needs to be disabled initially, which is not viable in the existing test file. |
plugins/webp-uploads/tests/test-picture-element-original-fallback.php
Outdated
Show resolved
Hide resolved
plugins/webp-uploads/tests/test-picture-element-original-fallback.php
Outdated
Show resolved
Hide resolved
plugins/webp-uploads/tests/test-picture-element-original-fallback.php
Outdated
Show resolved
Hide resolved
… fix/1447-skip-picture-if-no-jpeg
plugins/webp-uploads/settings.php
Outdated
| </label> | ||
| <p class="description" id="webp_uploads_use_picture_element_description"><?php esc_html_e( 'The picture element serves a modern image format with a fallback to JPEG. Warning: Make sure you test your theme and plugins for compatibility. In particular, CSS selectors will not match images when using the child combinator (e.g. figure > img).', 'webp-uploads' ); ?></p> | ||
| <div id="webp_uploads_jpeg_fallback_notice" class="notice notice-info inline" <?php echo $picture_element_enabled ? '' : 'hidden'; ?>> | ||
| <p><?php esc_html_e( 'Picture elements will only be used when JPEG fallback images are available. So this will not apply to any images you uploaded while the "Also generate JPEG" setting was disabled.', 'webp-uploads' ); ?></p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another slight copy improvement:
| <p><?php esc_html_e( 'Picture elements will only be used when JPEG fallback images are available. So this will not apply to any images you uploaded while the "Also generate JPEG" setting was disabled.', 'webp-uploads' ); ?></p> | |
| <p><?php esc_html_e( 'Picture elements will only be used when JPEG fallback images are available. So this will not apply to any images you may have uploaded while the "Also generate JPEG" setting was disabled.', 'webp-uploads' ); ?></p> |
… fix/1447-skip-picture-if-no-jpeg
|
@sagarnasit Have you replicate https://github.com/WordPress/performance/actions/runs/10364966081/job/28691196072?pr=1450#step:9:290 unit test failed in PHP 8.3 in your local? I didn't replicate it 🤔
|
|
@mukeshpanchal27 The issue is not with PHP 8.3 but with the WordPress trunk. I tried to load the WordPress trunk on a local setup and was able to replicate the issue with the following. I also attempted to debug further, but I was unsuccessful in finding out why |
|
Probably a regression in the HTML Tag Processor in WP Core |
|
Doing so now... |
|
For reference, the unit test assertion is failing here: performance/plugins/webp-uploads/tests/test-picture-element-original-fallback.php Lines 79 to 80 in da7d55f
The markup contained in <p><img width="1024" height="683" src="http://localhost:8889/wp-content/uploads/2024/08/leaves-232-1024x683.webp" class="wp-image-9" alt="Green Leaves" decoding="async" loading="lazy" srcset="http://localhost:8889/wp-content/uploads/2024/08/leaves-232-1024x683.webp 1024w, http://localhost:8889/wp-content/uploads/2024/08/leaves-232-300x200.webp 300w, http://localhost:8889/wp-content/uploads/2024/08/leaves-232-768x512.webp 768w, http://localhost:8889/wp-content/uploads/2024/08/leaves-232-jpg.webp 1080w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>With formatting: <p>
<img
width="1024"
height="683"
src="http://localhost:8889/wp-content/uploads/2024/08/leaves-232-1024x683.webp"
class="wp-image-9"
alt="Green Leaves"
decoding="async"
loading="lazy"
srcset="
http://localhost:8889/wp-content/uploads/2024/08/leaves-232-1024x683.webp 1024w,
http://localhost:8889/wp-content/uploads/2024/08/leaves-232-300x200.webp 300w,
http://localhost:8889/wp-content/uploads/2024/08/leaves-232-768x512.webp 768w,
http://localhost:8889/wp-content/uploads/2024/08/leaves-232-jpg.webp 1080w
"
sizes="(max-width: 1024px) 100vw, 1024px"
/>
</p>There is definitely no And yet, for some reason, |
|
It's WP Trunk error not related to PHP version. I have open WordPress/wordpress-develop#7185 to verify that. |
|
Given this code: $picture_markup = '<p><img width="1024" height="683" src="http://localhost:8889/wp-content/uploads/2024/08/leaves-232-1024x683.webp" class="wp-image-9" alt="Green Leaves" decoding="async" loading="lazy" srcset="http://localhost:8889/wp-content/uploads/2024/08/leaves-232-1024x683.webp 1024w, http://localhost:8889/wp-content/uploads/2024/08/leaves-232-300x200.webp 300w, http://localhost:8889/wp-content/uploads/2024/08/leaves-232-768x512.webp 768w, http://localhost:8889/wp-content/uploads/2024/08/leaves-232-jpg.webp 1080w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>';
$picture_processor = new WP_HTML_Tag_Processor( $picture_markup );
var_dump( $picture_processor->next_tag( array( 'tag_name' => 'picture' ) ) );
var_dump( $picture_processor->get_tag() );It outputs: If I remove the So it seems that the Tag Processor is only looking at the first character of the tag name now, which is a bug. Quick workaround to get the tests to pass: remove the |
|
Reported upstream: https://core.trac.wordpress.org/ticket/61545#comment:6 |
plugins/webp-uploads/tests/test-picture-element-original-fallback.php
Outdated
Show resolved
Hide resolved
|
✅ Behavior looks good. Before: <picture
class="not-transparent wp-picture-155"
style="--dominant-color: #594e4a; display: contents"
><source
type="image/webp"
srcset="
http://localhost:8888/wp-content/uploads/2024/08/image-1-jpeg.webp 1300w,
http://localhost:8888/wp-content/uploads/2024/08/image-1-300x201.webp 300w,
http://localhost:8888/wp-content/uploads/2024/08/image-1-1024x688.webp 1024w,
http://localhost:8888/wp-content/uploads/2024/08/image-1-768x516.webp 768w
"
sizes="(max-width: 650px) 100vw, 650px" />
<img
data-dominant-color="594e4a"
data-has-transparency="false"
decoding="async"
width="1300"
height="873"
src="http://localhost:8888/wp-content/uploads/2024/08/image-1-jpeg.webp"
alt=""
class="not-transparent wp-image-155"
srcset="
http://localhost:8888/wp-content/uploads/2024/08/image-1-jpeg.webp 1300w,
http://localhost:8888/wp-content/uploads/2024/08/image-1-300x201.webp 300w,
http://localhost:8888/wp-content/uploads/2024/08/image-1-1024x688.webp 1024w,
http://localhost:8888/wp-content/uploads/2024/08/image-1-768x516.webp 768w
"
sizes="(max-width: 650px) 100vw, 650px"
/></picture>After: <img
data-dominant-color="594e4a"
data-has-transparency="false"
style="--dominant-color: #594e4a"
decoding="async"
width="1300"
height="873"
src="http://localhost:8888/wp-content/uploads/2024/08/image-1-jpeg.webp"
alt=""
class="not-transparent wp-image-155"
srcset="
http://localhost:8888/wp-content/uploads/2024/08/image-1-jpeg.webp 1300w,
http://localhost:8888/wp-content/uploads/2024/08/image-1-300x201.webp 300w,
http://localhost:8888/wp-content/uploads/2024/08/image-1-1024x688.webp 1024w,
http://localhost:8888/wp-content/uploads/2024/08/image-1-768x516.webp 768w
"
sizes="(max-width: 650px) 100vw, 650px"
/>Settings screen: |
|
#1450 (comment) the core issue is fixed now in https://core.trac.wordpress.org/changeset/58893 |


Summary
This PR accounts following:
Fixes #1447