From fcd1b9a06bee787cdcf5b9cec1880af4bb0c4125 Mon Sep 17 00:00:00 2001 From: himanshupathak95 Date: Thu, 13 Feb 2025 12:56:00 +0530 Subject: [PATCH] Global Styles: Defer revisions for font activation until explicit save --- .../global-styles/font-library-modal/context.js | 17 +++++++++++------ 1 file changed, 11 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 abfb5484e44bf..4d01c1326cbee 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 @@ -93,7 +93,7 @@ function FontLibraryProvider( { children } ) { * * @param {Array} fonts - The font families that will be saved to the database. */ - const saveFontFamilies = async ( fonts ) => { + const saveFontFamilies = async ( fonts, shouldAutoSave = false ) => { // Gets the global styles database post content. const updatedGlobalStyles = globalStyles.record; @@ -104,8 +104,14 @@ function FontLibraryProvider( { children } ) { fonts ); - // Saves a new version of the global styles in the database. - await saveEntityRecord( 'root', 'globalStyles', updatedGlobalStyles ); + if ( shouldAutoSave ) { + // Saves a new version of the global styles in the database. + await saveEntityRecord( + 'root', + 'globalStyles', + updatedGlobalStyles + ); + } }; // Library Fonts @@ -309,8 +315,7 @@ function FontLibraryProvider( { children } ) { fontFamiliesToActivate ); // Save the global styles to the database. - await saveFontFamilies( activeFonts ); - + await saveFontFamilies( activeFonts, true ); refreshLibrary(); } @@ -343,7 +348,7 @@ function FontLibraryProvider( { children } ) { fontFamilyToUninstall ); // Save the global styles to the database. - await saveFontFamilies( activeFonts ); + await saveFontFamilies( activeFonts, true ); } // Refresh the library (the library font families from database).