@@ -495,6 +495,7 @@ function idSystemInitializer({ mkDelay = delay } = {}) {
495495 const startInit = defer < void > ( ) ;
496496 const startCallbacks = defer < void > ( ) ;
497497 let cancel ;
498+ let initStarted = false ;
498499 let initialized = false ;
499500 let initMetrics ;
500501
@@ -531,6 +532,7 @@ function idSystemInitializer({ mkDelay = delay } = {}) {
531532 PbPromise . all ( [ hooksReady , startInit . promise ] )
532533 . then ( timeConsent )
533534 . then ( checkRefs ( ( ) => {
535+ initialized = true ;
534536 initSubmodules ( initModules , allModules ) ;
535537 } ) )
536538 . then ( ( ) => startCallbacks . promise . finally ( initMetrics . startTiming ( 'userId.callbacks.pending' ) ) )
@@ -547,8 +549,8 @@ function idSystemInitializer({ mkDelay = delay } = {}) {
547549 * filtered by `submoduleNames`).
548550 */
549551 return function ( { refresh = false , submoduleNames = null , ready = false } = { } ) {
550- if ( ready && ! initialized ) {
551- initialized = true ;
552+ if ( ready && ! initStarted ) {
553+ initStarted = true ;
552554 startInit . resolve ( ) ;
553555 // submodule callbacks should run immediately if `auctionDelay` > 0, or `syncDelay` ms after the
554556 // auction ends otherwise
@@ -765,8 +767,13 @@ function registerSignalSources() {
765767}
766768
767769function retryOnCancel ( initParams ?) {
768- return initIdSystem ( initParams ) . then (
769- ( ) => getUserIds ( ) ,
770+ const ready = initIdSystem ( initParams ) ;
771+ return ready . then (
772+ ( ) => {
773+ // if something has changed, try again
774+ const updated = initIdSystem ( ) ;
775+ return updated === ready ? getUserIds ( ) : retryOnCancel ( ) ;
776+ } ,
770777 ( e ) => {
771778 if ( e === INIT_CANCELED ) {
772779 // there's a pending refresh - because GreedyPromise runs this synchronously, we are now in the middle
@@ -1254,6 +1261,9 @@ export function init(config, { mkDelay = delay } = {}) {
12541261 configRegistry = [ ] ;
12551262 initializedSubmodules = mkPriorityMaps ( ) ;
12561263 initIdSystem = idSystemInitializer ( { mkDelay } ) ;
1264+ allConsent . onChange ( ( ) => {
1265+ initIdSystem ( { refresh : true } ) ;
1266+ } )
12571267 if ( configListener != null ) {
12581268 configListener ( ) ;
12591269 }
0 commit comments