Skip to content

Commit

Permalink
Font Library: install fonts in sequence to work around race condition (
Browse files Browse the repository at this point in the history
…WordPress#60180)

* Font Library: install fonts in sequence to work around font directory race condition

* Update comment block to coding standards

Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com>

* Fix linting

---------

Co-authored-by: creativecoder <grantmkin@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>
Co-authored-by: mcsf <mcsf@git.wordpress.org>
Co-authored-by: peterwilsoncc <peterwilsoncc@git.wordpress.org>
Co-authored-by: mikachan <mikachan@git.wordpress.org>
Co-authored-by: huzaifaalmesbah <huzaifaalmesbah@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
Co-authored-by: kjnanda <krupajnanda@git.wordpress.org>
Co-authored-by: matiasbenedetto <mmaattiiaass@git.wordpress.org>
  • Loading branch information
11 people authored and carstingaxion committed Mar 27, 2024
1 parent 5a77576 commit 7517585
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,23 @@ export function makeFontFacesFormData( font ) {
}

export async function batchInstallFontFaces( fontFamilyId, fontFacesData ) {
const promises = fontFacesData.map( ( faceData ) =>
fetchInstallFontFace( fontFamilyId, faceData )
);
const responses = await Promise.allSettled( promises );
const responses = [];

/*
* Uses the same response format as Promise.allSettled, but executes requests in sequence to work
* around a race condition that can cause an error when the fonts directory doesn't exist yet.
*/
for ( const faceData of fontFacesData ) {
try {
const response = await fetchInstallFontFace(
fontFamilyId,
faceData
);
responses.push( { status: 'fulfilled', value: response } );
} catch ( error ) {
responses.push( { status: 'rejected', reason: error } );
}
}

const results = {
errors: [],
Expand Down

0 comments on commit 7517585

Please sign in to comment.