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

Show alert when avif file is used in social preview #21962

Merged

Conversation

pls78
Copy link
Member

@pls78 pls78 commented Jan 10, 2025

Context

  • AVIF file are currently not supported by Facebook and X: we want to warn users when their fallback image is in that format.

Summary

This PR can be summarized in the following changelog entry:

  • Issues a warning message when the image automatically selected for a post social preview is in the unsupported AVIF format.
  • [@yoast/components 0.0.1] Refactors the logic used by ImageSelect to determine which styling to apply.
  • [@yoast/social-metadata-forms 0.0.1 other] Adds usingFallback prop to SocialMetadataPreviewForm component.
  • [@yoast/social-metadata-previews 0.0.1 other] Passes imageFallbackUrl prop to SocialPreviewEditor component.

Relevant technical choices:

  • I implemented this check in the warppers (FacebookWrapper and TwitterWrapper) because it wouldn't make sense to have it in the more general ImageSelect component, as this limitation is specific to our implementation.
  • I opted to use the already-existing warning infrastructure which is currently used to display warnings about images that are manually selected by the user
    • I directly manipulate use the props.imageWarnings array instead of using an action because:
    • currently there's no dedicated action to set warnings: warnings are set atomically with image selection in selectMedia prepareFacebookPreviewImage and prepareTwitterPreviewImage functions: refactoring this would require a non-negligible effort which is out of the scope of this PR. Moreover, the imageWarnings array is drilled down throughout the components' chain where it is needed.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

  • Check against UX design
  • Edit a post and make sure you did not select any image for its social previews (both Facebook and X)
  • Drag and drop an AVIF image into the post, so that is being used as fallback for the social preview (you can download some sample AVIF files from here)
  • Go to the Social tab in the Metabox and verify you see the following warning:
    Screenshot 2025-01-23 at 10 15 15
  • Check you see the same warning in the X appearance section, too
  • Click on Select image and select any image of a supported type
    • Check the warning is gone
  • Click on Remove image and check the warning is back
  • Click on Select image and select an image of AVIF type (you can select the same image you used in the post)
    • Check the warning is now as follows:
    Screenshot 2025-01-17 at 16 05 54
  • Restore the post to have no images for its social previews and an AVIF image in its body
  • Open the Social media appearance modal from the Yoast Sidebar
    • Check the warning is present there, too
  • Remove the AVIF image from the post body and use it as featured image instead
    • Perform the same checks as above
  • Perform the same tests in Elementor and Classic editor
  • Perform the same tests with Premium activated. To do so:
    • Remove the folder wordpress-seo in your Premium's vendor/yoast folder
    • in vendor/yoast create a symlink to the wordpress-seo folder installation containing this branch

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

QA can test this PR by following these steps:

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

UI changes

  • This PR changes the UI in the plugin. I have added the 'UI change' label to this PR.

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.

Documentation

  • I have written documentation for this change. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests to verify the code works as intended.
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.
  • I have checked that the base branch is correctly set.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes #4496

@pls78 pls78 added the changelog: enhancement Needs to be included in the 'Enhancements' category in the changelog label Jan 10, 2025
Copy link

@pls78 Please be aware that following packages have been abandoned and are not actively maintained anymore:

Package name Path
@yoast/babel-preset packages/babel-preset
@yoast/components packages/components
@yoast/e2e-tests packages/e2e-tests
@yoast/helpers packages/helpers
@yoast/jest-preset packages/jest-preset
@yoast/style-guide packages/style-guide

Please consider using the other packages instead.

@coveralls
Copy link

coveralls commented Jan 10, 2025

Pull Request Test Coverage Report for Build 8f7622d3032382f4c7cf0b383c928dc67bc300b7

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 4 of 17 (23.53%) changed or added relevant lines in 4 files are covered.
  • 19 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.04%) to 54.58%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/components/src/image-select/ImageSelect.js 4 5 80.0%
packages/js/src/components/social/FacebookWrapper.js 0 3 0.0%
packages/js/src/components/social/TwitterWrapper.js 0 3 0.0%
packages/js/src/components/social/useFallbackWarning.js 0 6 0.0%
Files with Coverage Reduction New Missed Lines %
packages/js/src/components/social/TwitterWrapper.js 2 0.0%
packages/js/src/ai-assessment-fixes/components/ai-assessment-fixes-button.js 5 80.0%
packages/js/src/components/fills/SidebarFill.js 5 0.0%
packages/js/src/components/fills/MetaboxFill.js 7 0.0%
Totals Coverage Status
Change from base Build abf031a7bd7917bce37c0e48b7e194c1fc89b41d: -0.04%
Covered Lines: 30081
Relevant Lines: 55473

💛 - Coveralls

Copy link

@pls78 Please be aware that following packages have been abandoned and are not actively maintained anymore:

Package name Path
@yoast/babel-preset packages/babel-preset
@yoast/components packages/components
@yoast/e2e-tests packages/e2e-tests
@yoast/helpers packages/helpers
@yoast/jest-preset packages/jest-preset
@yoast/style-guide packages/style-guide

Please consider using the other packages instead.

Copy link

@pls78 Please be aware that following packages have been abandoned and are not actively maintained anymore:

Package name Path
@yoast/babel-preset packages/babel-preset
@yoast/components packages/components
@yoast/e2e-tests packages/e2e-tests
@yoast/helpers packages/helpers
@yoast/jest-preset packages/jest-preset
@yoast/style-guide packages/style-guide

Please consider using the other packages instead.

@pls78 pls78 marked this pull request as ready for review January 13, 2025 12:01
Copy link
Member

@igorschoester igorschoester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR 🏗️

Regarding the size warning we have. Should that not also be checked for the fallback, while you are at it?

Regarding your tech choices:

I implemented this check in the warppers (FacebookWrapper and TwitterWrapper) because it wouldn't make sense to have it in the more general ImageSelect component

Why does that not make sense?

refactoring this wouldn't make much sense also because the imageWarnings array is drilled down throughout the components' chain

Why would that stop you? You just need to adapt the source, i.e. the selector. Right?
Just thinking a bit on alternative solutions:

  • You could make getFacebookWarnings and the like accept a second variable, the fallback URL. And then do this there. I'm not actually suggesting that is great, I'm just trying to get you to think a bit more inline with the current solutions.
  • Perhaps the warnings should always be calculated in a memoized selector. And taken out of the current set image with warning.
  • Perhaps it is worth just adding a set warning action.
  • Perhaps the prepareFacebookPreviewImage should encompass the fallback already so it can try to assess it too

@pls78
Copy link
Member Author

pls78 commented Jan 14, 2025

CR 🏗️

Regarding the size warning we have. Should that not also be checked for the fallback, while you are at it?

Regarding your tech choices:

I implemented this check in the warppers (FacebookWrapper and TwitterWrapper) because it wouldn't make sense to have it in the more general ImageSelect component

Why does that not make sense?

Because the ImageSelect component doesn't need to (must not, I dare to say) know about application-specific logic: in our case we perform a check about the AVIF file format because the ImageSelect component is used inside our Social Appearance component, which is about Facebook and X, and both of them don't support the AVIF format.

refactoring this wouldn't make much sense also because the imageWarnings array is drilled down throughout the components' chain

Why would that stop you? You just need to adapt the source, i.e. the selector. Right? Just thinking a bit on alternative solutions:

* You could make `getFacebookWarnings` and the like accept a second variable, the fallback URL. And then do this there. I'm not actually suggesting that is great, I'm just trying to get you to think a bit more inline with the current solutions.

I don't know... it seems a bit "dirty" to me because getFacebookWarnings is just a getter, the warning is actually set when the image gets selected and validated. It feels odd to me adding the check about the fallback in it while the other checks about the "regular" image live somewhere else...

* Perhaps the warnings should always be calculated in a memoized selector. And taken out of the current set image with warning.

I considered it but I usually adopt a "least-impactful" approach when dealing with ancient code (personal choice).

* Perhaps it is worth just adding a set warning action.

Because the warning array is drilled down where I need it already.

* Perhaps the `prepareFacebookPreviewImage` should encompass the fallback already so it can try to assess it too

This is a suggestion I can agree upon 😁

In general, I felt that the fact the warnings array is available throughout the whole components hierarchy up to where I need it would make useless to add a selector. Moreover, we (currently) don't use it outside this hierarchy neither.

Copy link

@pls78 Please be aware that following packages have been abandoned and are not actively maintained anymore:

Package name Path
@yoast/babel-preset packages/babel-preset
@yoast/components packages/components
@yoast/e2e-tests packages/e2e-tests
@yoast/helpers packages/helpers
@yoast/jest-preset packages/jest-preset
@yoast/style-guide packages/style-guide

Please consider using the other packages instead.

Copy link

@pls78 Please be aware that following packages have been abandoned and are not actively maintained anymore:

Package name Path
@yoast/babel-preset packages/babel-preset
@yoast/components packages/components
@yoast/e2e-tests packages/e2e-tests
@yoast/helpers packages/helpers
@yoast/jest-preset packages/jest-preset
@yoast/style-guide packages/style-guide

Please consider using the other packages instead.

Copy link

@pls78 Please be aware that following packages have been abandoned and are not actively maintained anymore:

Package name Path
@yoast/babel-preset packages/babel-preset
@yoast/components packages/components
@yoast/e2e-tests packages/e2e-tests
@yoast/helpers packages/helpers
@yoast/jest-preset packages/jest-preset
@yoast/style-guide packages/style-guide

Please consider using the other packages instead.

Copy link

@pls78 Please be aware that following packages have been abandoned and are not actively maintained anymore:

Package name Path
@yoast/babel-preset packages/babel-preset
@yoast/components packages/components
@yoast/e2e-tests packages/e2e-tests
@yoast/helpers packages/helpers
@yoast/jest-preset packages/jest-preset
@yoast/style-guide packages/style-guide

Please consider using the other packages instead.

Copy link

@pls78 Please be aware that following packages have been abandoned and are not actively maintained anymore:

Package name Path
@yoast/babel-preset packages/babel-preset
@yoast/components packages/components
@yoast/e2e-tests packages/e2e-tests
@yoast/helpers packages/helpers
@yoast/jest-preset packages/jest-preset
@yoast/style-guide packages/style-guide

Please consider using the other packages instead.

Copy link

@pls78 Please be aware that following packages have been abandoned and are not actively maintained anymore:

Package name Path
@yoast/babel-preset packages/babel-preset
@yoast/components packages/components
@yoast/e2e-tests packages/e2e-tests
@yoast/helpers packages/helpers
@yoast/jest-preset packages/jest-preset
@yoast/style-guide packages/style-guide

Please consider using the other packages instead.

Copy link
Member

@igorschoester igorschoester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR 🏗️

About the changelog entries for the social packages:

  • The props are all lowercase. You have capitalized them in the changelog, why?
  • The previews is just passing the image fallback. IF that deserves a changelog entry, maybe make it clear it is not adding a prop at all. It is passing the prop.

packages/js/src/components/social/useFallbackWarning.js Outdated Show resolved Hide resolved
packages/js/src/components/social/useFallbackWarning.js Outdated Show resolved Hide resolved
Copy link

@pls78 Please be aware that following packages have been abandoned and are not actively maintained anymore:

Package name Path
@yoast/babel-preset packages/babel-preset
@yoast/components packages/components
@yoast/e2e-tests packages/e2e-tests
@yoast/helpers packages/helpers
@yoast/jest-preset packages/jest-preset
@yoast/style-guide packages/style-guide

Please consider using the other packages instead.

Copy link

@pls78 Please be aware that following packages have been abandoned and are not actively maintained anymore:

Package name Path
@yoast/babel-preset packages/babel-preset
@yoast/components packages/components
@yoast/e2e-tests packages/e2e-tests
@yoast/helpers packages/helpers
@yoast/jest-preset packages/jest-preset
@yoast/style-guide packages/style-guide

Please consider using the other packages instead.

Copy link
Member

@igorschoester igorschoester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AT 🚧

Detected some problems:

  • The AVIF in the content is not being picked up in Elementor as a fallback, so no warnings are displayed
    • it does work when adding as social image
    • might be unrelated to your PR so far 😓
  • The copy of the warning is a bit strange. When selecting an AVIF image as Social image, the X image warning mentions it coming from the content. While we have no mechanism to determine where the fallback came from we now specify this in the message??
  • When activating Premium the whole AVIF warnings don't work anymore. I'm presuming Premium needs to be build with this code from Free in order to fix that. But no test instructions or anything to indicate that

Copy link

@pls78 Please be aware that following packages have been abandoned and are not actively maintained anymore:

Package name Path
@yoast/babel-preset packages/babel-preset
@yoast/components packages/components
@yoast/e2e-tests packages/e2e-tests
@yoast/helpers packages/helpers
@yoast/jest-preset packages/jest-preset
@yoast/style-guide packages/style-guide

Please consider using the other packages instead.

Copy link
Member

@igorschoester igorschoester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AT ✅

@igorschoester igorschoester merged commit ca4dc5f into trunk Jan 27, 2025
18 checks passed
@igorschoester igorschoester deleted the show-alert-when-avif-file-is-used-in-social-preview branch January 27, 2025 09:40
@igorschoester igorschoester added this to the 24.5 milestone Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: enhancement Needs to be included in the 'Enhancements' category in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants