From 6f6255167810b7a304454376748a815b55824e6a Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 21 Mar 2024 16:34:25 -0300 Subject: [PATCH 1/2] Activate the fonts coming from the backend and not the data from the frontend --- .../font-library-modal/context.js | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/context.js b/packages/edit-site/src/components/global-styles/font-library-modal/context.js index dc593c7dfbb29..7da92abdc5ceb 100644 --- a/packages/edit-site/src/components/global-styles/font-library-modal/context.js +++ b/packages/edit-site/src/components/global-styles/font-library-modal/context.js @@ -281,11 +281,11 @@ function FontLibraryProvider( { children } ) { sucessfullyInstalledFontFaces?.length > 0 || alreadyInstalledFontFaces?.length > 0 ) { - fontFamilyToInstall.fontFace = [ + installedFontFamily.fontFace = [ ...sucessfullyInstalledFontFaces, - ...alreadyInstalledFontFaces, ]; - fontFamiliesToActivate.push( fontFamilyToInstall ); + + fontFamiliesToActivate.push( installedFontFamily ); } // If it's a system font but was installed successfully, activate it. @@ -402,14 +402,29 @@ function FontLibraryProvider( { children } ) { }; const activateCustomFontFamilies = ( fontsToAdd ) => { - // Merge the existing custom fonts with the new fonts. + // Removes the id from the families and faces to avoid saving that to global styles post content. + const fontsToActivate = fontsToAdd.map( + ( { id: _familyDbId, fontFace, ...font } ) => ( { + ...font, + ...( fontFace && fontFace.length > 0 + ? { + fontFace: fontFace.map( + ( { id: _faceDbId, ...face } ) => face + ), + } + : {} ), + } ) + ); + // Activate the fonts by set the new custom fonts array. setFontFamilies( { ...fontFamilies, - custom: mergeFontFamilies( fontFamilies?.custom, fontsToAdd ), + // Merge the existing custom fonts with the new fonts. + custom: mergeFontFamilies( fontFamilies?.custom, fontsToActivate ), } ); + // Add custom fonts to the browser. - fontsToAdd.forEach( ( font ) => { + fontsToActivate.forEach( ( font ) => { if ( font.fontFace ) { font.fontFace.forEach( ( face ) => { // Load font faces just in the iframe because they already are in the document. From f51caea8580330e83b2e93bb7a07bc9a71f1f8c1 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Mon, 25 Mar 2024 08:47:19 -0300 Subject: [PATCH 2/2] add comment Co-authored-by: Dave Smith --- .../src/components/global-styles/font-library-modal/context.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/context.js b/packages/edit-site/src/components/global-styles/font-library-modal/context.js index 7da92abdc5ceb..ff8cfc1284b1e 100644 --- a/packages/edit-site/src/components/global-styles/font-library-modal/context.js +++ b/packages/edit-site/src/components/global-styles/font-library-modal/context.js @@ -281,6 +281,8 @@ function FontLibraryProvider( { children } ) { sucessfullyInstalledFontFaces?.length > 0 || alreadyInstalledFontFaces?.length > 0 ) { + // Use font data from REST API not from client to ensure + // correct font information is used. installedFontFamily.fontFace = [ ...sucessfullyInstalledFontFaces, ];