-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 font uninstallation #56762
Conversation
Size Change: +2 B (0%) Total Size: 1.72 MB
ℹ️ View Unchanged
|
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.
This is working as expected with the if ( 0 === response.errors.length )
check. I think it would be better to omit the other change because it could lead to confusion in cases where, for some reason, there are fonts in global styles that are not installed in the library.
.filter( ( f ) => | ||
baseCustomFonts.some( ( bf ) => bf.slug === f.slug ) | ||
) // Ensures that the font actually exists in the library. |
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.
Do you think this is necessary? I think it could lead to some inconsistencies like not displaying a font that is still activated (in global styles) but not installed.
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.
I think it could lead to some inconsistencies like not displaying a font that is still activated (in global styles) but not installed.
This is what happens now / on trunk. Without this line — if the font uninstallation fails, it will still display the activated font in the typography sidebar.
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.
I see what you mean though, I'll remove it for now and find another way to address it if there are issues later.
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.
if the font uninstallation fails, it will still display the activated font in the typography sidebar.
I think that's correct, if the font was not uninstalled, it should still render because it will continue being active, right?
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.
Not quite — the way this is failing, is that the font gets uninstalled successfully on the server side, but not in global styles since that is handled client side and that's where the bug is. The result is the font family is uninstalled and deleted, but is still defined in global styles / shows up in the sidebar.
@@ -229,7 +232,7 @@ function FontLibraryProvider( { children } ) { | |||
// Uninstall the font (remove the font files from the server and the post from the database). | |||
const response = await fetchUninstallFonts( [ font ] ); | |||
// Deactivate the font family (remove the font family from the global styles). | |||
if ( ! response.errors ) { | |||
if ( 0 === response.errors.length ) { |
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.
Nice catch
c449b0d
to
842f754
Compare
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.
It looks good to me and is working as expected.
Flaky tests detected in 842f754. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7103784108
|
What?
This PR fixes a bug in the
uninstallFont
function of the FontLibraryProvider class.It also adds some logic to ensure that only custom fonts that are actually installed are ever rendered to the client.Why?
Fixes #56166
How?
In the uninstallFonts function, check the response errors array for length.
In the context, filter out fonts that are not installed.Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast