Directory

Font Library: fix duplicate variants by jffng · Pull Request #54320 · WordPress/gutenberg · GitHub
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

Font Library: fix duplicate variants #54320

Closed
wants to merge 119 commits into from
Closed

Conversation

jffng
Copy link
Contributor

@jffng jffng commented Sep 8, 2023

What?

This PR adds checks to ensure that multiple file types of the same font variant are not added, so that only one variation per font style and weight is stored.

Why?

Fixes #54253

How?

For fonts where the font family does not yet exist, checks the list of new font faces and compares their font weight and style, and if there is already an existing font face, skips adding the incoming one.

For font faces where the font family exists, adds a new function get_intersecting_font_faces which returns an array of font faces to be deleted and replaced by the incoming font face.

Testing Instructions

  1. Simultaneously (batch) upload two or more font faces of the same family, style, and weight, but different file types.
  2. Ensure only the first variant is added / used.
  3. Upload a font face to an existing font family with the same style and weight, but different file type.
  4. Ensure the uploaded version is used / replaces the existing one, and an additional variant is not created.

Testing Instructions for Keyboard

Screenshots or screencast

matiasbenedetto and others added 30 commits August 14, 2023 16:49
Co-authored-by: Tonya Mork <tonya.mork@automattic.com>
@jffng jffng force-pushed the fix/duplicate-variants-file-ext branch from 3881631 to f72d258 Compare September 12, 2023 21:43
@jffng jffng marked this pull request as ready for review September 12, 2023 22:00
* @param array $incoming The incoming font faces.
* @return array The font faces that are in both the existing and incoming font families.
*/
private function get_intersecting_font_faces( $existing, $incoming ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I add a test for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we are not testing private class methods, and I also don't know if there is an easy way to do that and if we should do it. I would prefer to add a test case(s) for the public method (install) that covers the situations we are trying to fix with the changes in this PR.

@mikachan mikachan added Needs PHP backport Needs PHP backport to Core [Feature] Typography Font and typography-related issues and PRs labels Sep 13, 2023
@github-actions
Copy link

Flaky tests detected in 83bff3d.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6186790338
📝 Reported issues:

Base automatically changed from try/fonts-library-frontend-stage1 to trunk September 14, 2023 19:45
@jffng
Copy link
Contributor Author

jffng commented Sep 15, 2023

The rebase on this PR got ugly after the frontend was merged, so I opened a new PR at #54490.

Closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Typography Font and typography-related issues and PRs [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Font Library: Same font faces with different file extensions are added as a separated variant.
7 participants