55import { replaceKey } from '../../features/placeholders.js' ;
66
77// MAS Component Names
8- export const MAS_COMMERCE_SERVICE = 'commerce' ;
8+ export const COMMERCE_LIBRARY = 'commerce' ;
99export const MAS_MERCH_CARD = 'merch-card' ;
1010export const MAS_MERCH_CARD_COLLECTION = 'merch-card-collection' ;
1111export const MAS_MERCH_MNEMONIC_LIST = 'merch-mnemonic-list' ;
@@ -373,7 +373,7 @@ export function getMasLibs() {
373373 const sanitizedMasLibs = masLibs . trim ( ) . toLowerCase ( ) ;
374374
375375 if ( sanitizedMasLibs === 'local' ) {
376- return 'http://localhost:3030 /web-components/dist' ;
376+ return 'http://localhost:3000 /web-components/dist' ;
377377 }
378378 if ( sanitizedMasLibs === 'main' ) {
379379 return 'http://www.adobe.com/mas/libs' ;
@@ -405,7 +405,7 @@ function getFragmentClientUrl() {
405405 const sanitizedMasLibs = masLibs . trim ( ) . toLowerCase ( ) ;
406406
407407 if ( sanitizedMasLibs === 'local' ) {
408- return 'http://localhost:3030 /studio/libs/fragment-client.js' ;
408+ return 'http://localhost:3000 /studio/libs/fragment-client.js' ;
409409 }
410410 if ( sanitizedMasLibs === 'main' ) {
411411 return 'https://mas.adobe.com/studio/libs/fragment-client.js' ;
@@ -432,59 +432,40 @@ const failedExternalLoads = new Set();
432432const loadingPromises = new Map ( ) ;
433433
434434/**
435- * Checks if mas-ff-mas-deps feature flag is enabled
436- * @returns {boolean } true if flag is on
437- */
438- function isMasDepsFlagEnabled ( ) {
439- const metaFlag = getMetadata ( 'mas-ff-mas-deps' ) ;
440- if ( metaFlag === 'off' || metaFlag === 'false' ) return false ;
441- return true ;
442- }
443-
444- /**
445- * Loads a MAS component either from external URL (if masLibs present) or local deps
435+ * Loads a MAS component either from external URL (if masLibs present) or from production CDN
446436 * @param {string } componentName - Name of the component to load (e.g., 'commerce', 'merch-card')
447437 * @returns {Promise } Promise that resolves when component is loaded
448438 */
449439export async function loadMasComponent ( componentName ) {
440+ // Return existing loading promise if already in progress
450441 if ( loadingPromises . has ( componentName ) ) {
451442 return loadingPromises . get ( componentName ) ;
452443 }
453444
445+ // Component already loaded, return immediately
454446 if ( customElements . get ( componentName ) ) {
455447 return Promise . resolve ( ) ;
456448 }
457449
458450 const loadPromise = ( async ( ) => {
459451 const masLibsBase = getMasLibs ( ) ;
452+ const productionUrl = `https://www.adobe.com/mas/libs/${ componentName } .js` ;
453+ const targetUrl = masLibsBase ? `${ masLibsBase } /${ componentName } .js` : productionUrl ;
460454
461- if ( masLibsBase ) {
462- const externalUrl = `${ masLibsBase } /${ componentName } .js` ;
463-
464- if ( failedExternalLoads . has ( externalUrl ) ) {
465- throw new Error ( `Failed to load component from ${ externalUrl } ` ) ;
466- }
455+ // Fail fast if this URL has already failed before
456+ if ( failedExternalLoads . has ( targetUrl ) ) {
457+ throw new Error ( `Previously failed to load component from ${ targetUrl } ` ) ;
458+ }
467459
468- try {
469- return await import ( externalUrl ) ;
470- } catch ( error ) {
471- failedExternalLoads . add ( externalUrl ) ;
472- throw error ;
473- }
474- } else if ( isMasDepsFlagEnabled ( ) ) {
475- const masUrl = `https://www.adobe.com/mas/libs/${ componentName } .js` ;
476- try {
477- return await import ( masUrl ) ;
478- } catch ( error ) {
479- // eslint-disable-next-line no-console
480- console . warn ( `Failed to load from MAS repository, falling back to Milo deps: ${ error . message } ` ) ;
481- return import ( `../../deps/mas/${ componentName } .js` ) ;
482- }
483- } else {
484- return import ( `../../deps/mas/${ componentName } .js` ) ;
460+ try {
461+ return await import ( targetUrl ) ;
462+ } catch ( error ) {
463+ failedExternalLoads . add ( targetUrl ) ;
464+ throw error ;
485465 }
486466 } ) ( ) ;
487467
468+ // Cache the promise and clean up when done
488469 loadingPromises . set ( componentName , loadPromise ) ;
489470 loadPromise . finally ( ( ) => loadingPromises . delete ( componentName ) ) ;
490471
@@ -1083,7 +1064,7 @@ export async function initService(force = false, attributes = {}) {
10831064 } ) ;
10841065 initService . promise = initService . promise
10851066 ?? polyfills ( ) . then ( async ( ) => {
1086- await loadMasComponent ( MAS_COMMERCE_SERVICE ) ;
1067+ await loadMasComponent ( COMMERCE_LIBRARY ) ;
10871068
10881069 // Load fragment-client.js when maslibs is present
10891070 const fragmentClientUrl = getFragmentClientUrl ( ) ;
0 commit comments