Skip to content

Commit

Permalink
Avoid creating font families without font faces. (#59436)
Browse files Browse the repository at this point in the history
If we ae trying to create a new font family with font faces but the font family was created in the database but the font faces failed because of the file system permissions, the font family is removed from the database.

---
Co-authored-by: matiasbenedetto <[email protected]>
Co-authored-by: mikachan <[email protected]>
  • Loading branch information
matiasbenedetto authored Feb 28, 2024
1 parent df5dc24 commit ab2123d
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ function FontLibraryProvider( { children } ) {

async function installFont( fontFamilyToInstall ) {
setIsInstalling( true );
let isANewFontFamily = false;
try {
// Get the font family if it already exists.
let installedFontFamily = await fetchGetFontFamilyBySlug(
Expand All @@ -210,6 +211,7 @@ function FontLibraryProvider( { children } ) {

// Otherwise create it.
if ( ! installedFontFamily ) {
isANewFontFamily = true;
// Prepare font family form data to install.
installedFontFamily = await fetchInstallFontFamily(
makeFontFamilyFormData( fontFamilyToInstall )
Expand Down Expand Up @@ -268,6 +270,11 @@ function FontLibraryProvider( { children } ) {
sucessfullyInstalledFontFaces.length === 0 &&
alreadyInstalledFontFaces.length === 0
) {
if ( isANewFontFamily ) {
// If the font family is new, delete it to avoid having font families without font faces.
await fetchUninstallFontFamily( installedFontFamily.id );
}

throw new Error(
sprintf(
/* translators: %s: Specific error message returned from server. */
Expand Down

0 comments on commit ab2123d

Please sign in to comment.