diff --git a/packages/block-directory/src/store/controls.js b/packages/block-directory/src/store/controls.js index e5b983642dbf5..19222b7b39aa3 100644 --- a/packages/block-directory/src/store/controls.js +++ b/packages/block-directory/src/store/controls.js @@ -62,7 +62,7 @@ export function loadAssets( assets ) { } const controls = { - LOAD_ASSETS() { + async LOAD_ASSETS() { /* * Fetch the current URL (post-new.php, or post.php?post=1&action=edit) and compare the * JavaScript and CSS assets loaded between the pages. This imports the required assets @@ -70,39 +70,28 @@ const controls = { * In the future this can be improved by reliance upon block.json and/or a script-loader * dependency API. */ - return apiFetch( { + const response = await apiFetch( { url: document.location.href, parse: false, - } ) - .then( ( response ) => response.text() ) - .then( ( data ) => { - const doc = new window.DOMParser().parseFromString( - data, - 'text/html' - ); + } ); + + const data = await response.text(); + + const doc = new window.DOMParser().parseFromString( data, 'text/html' ); - const newAssets = Array.from( - doc.querySelectorAll( 'link[rel="stylesheet"],script' ) - ).filter( - ( asset ) => - asset.id && ! document.getElementById( asset.id ) - ); + const newAssets = Array.from( + doc.querySelectorAll( 'link[rel="stylesheet"],script' ) + ).filter( + ( asset ) => asset.id && ! document.getElementById( asset.id ) + ); - return new Promise( async ( resolve, reject ) => { - for ( const i in newAssets ) { - try { - /* - * Load each asset in order, as they may depend upon an earlier loaded script. - * Stylesheets and Inline Scripts will resolve immediately upon insertion. - */ - await loadAsset( newAssets[ i ] ); - } catch ( e ) { - reject( e ); - } - } - resolve(); - } ); - } ); + /* + * Load each asset in order, as they may depend upon an earlier loaded script. + * Stylesheets and Inline Scripts will resolve immediately upon insertion. + */ + for ( const newAsset of newAssets ) { + await loadAsset( newAsset ); + } }, };