@@ -482,7 +482,9 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
482482 async #loadConfigurationSettings( loadFeatureFlag : boolean = false ) : Promise < ConfigurationSetting [ ] > {
483483 const selectors = loadFeatureFlag ? this . #ffSelectors : this . #kvSelectors;
484484 const funcToExecute = async ( client ) => {
485- const loadedSettings : ConfigurationSetting [ ] = [ ] ;
485+ // Use a Map to deduplicate configuration settings by key. When multiple selectors return settings with the same key,
486+ // the configuration setting loaded by the later selector in the iteration order will override the one from the earlier selector.
487+ const loadedSettings : Map < string , ConfigurationSetting > = new Map < string , ConfigurationSetting > ( ) ;
486488 // deep copy selectors to avoid modification if current client fails
487489 const selectorsToUpdate = JSON . parse (
488490 JSON . stringify ( selectors )
@@ -506,7 +508,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
506508 pageEtags . push ( page . etag ?? "" ) ;
507509 for ( const setting of page . items ) {
508510 if ( loadFeatureFlag === isFeatureFlag ( setting ) ) {
509- loadedSettings . push ( setting ) ;
511+ loadedSettings . set ( setting . key , setting ) ;
510512 }
511513 }
512514 }
@@ -528,7 +530,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
528530 for await ( const page of pageIterator ) {
529531 for ( const setting of page . items ) {
530532 if ( loadFeatureFlag === isFeatureFlag ( setting ) ) {
531- loadedSettings . push ( setting ) ;
533+ loadedSettings . set ( setting . key , setting ) ;
532534 }
533535 }
534536 }
@@ -540,7 +542,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
540542 } else {
541543 this . #kvSelectors = selectorsToUpdate ;
542544 }
543- return loadedSettings ;
545+ return Array . from ( loadedSettings . values ( ) ) ;
544546 } ;
545547
546548 return await this . #executeWithFailoverPolicy( funcToExecute ) as ConfigurationSetting [ ] ;
0 commit comments