Skip to content

Commit

Permalink
Font Library: fix JS errors when activating or deactivating system fo…
Browse files Browse the repository at this point in the history
…nts (#59935)

Co-authored-by: creativecoder <[email protected]>
Co-authored-by: madhusudhand <[email protected]>
Co-authored-by: mikachan <[email protected]>
  • Loading branch information
4 people authored Mar 18, 2024
1 parent a23bbeb commit d575ec7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,15 @@ function FontLibraryProvider( { children } ) {

const isFaceActivated = isFontActivated(
font.slug,
face.fontStyle,
face.fontWeight,
face?.fontStyle,
face?.fontWeight,
font.source
);

if ( isFaceActivated ) {
loadFontFaceInBrowser(
face,
getDisplaySrcFromFontFace( face.src ),
getDisplaySrcFromFontFace( face?.src ),
'all'
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ export function unloadFontFaceInBrowser( fontFace, removeFrom = 'all' ) {
const unloadFontFace = ( fonts ) => {
fonts.forEach( ( f ) => {
if (
f.family === formatFontFaceName( fontFace.fontFamily ) &&
f.weight === fontFace.fontWeight &&
f.style === fontFace.fontStyle
f.family === formatFontFaceName( fontFace?.fontFamily ) &&
f.weight === fontFace?.fontWeight &&
f.style === fontFace?.fontStyle
) {
fonts.delete( f );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export function formatFontFamily( input ) {
* formatFontFaceName(", 'Open Sans', 'Helvetica Neue', sans-serif") => "Open Sans"
*/
export function formatFontFaceName( input ) {
if ( ! input ) {
return '';
}

let output = input.trim();
if ( output.includes( ',' ) ) {
output = output
Expand Down

0 comments on commit d575ec7

Please sign in to comment.