@@ -328,8 +328,14 @@ export type InitOptions = ReflagDeprecatedContext & {
328328 maxSize ?: number ;
329329
330330 /**
331- * No retries are performed; failed batches are dropped .
331+ * Deprecated: retries are no longer performed for bulk delivery .
332332 */
333+ retryBaseDelayMs ?: number ;
334+
335+ /**
336+ * Deprecated: retries are no longer performed for bulk delivery.
337+ */
338+ retryMaxDelayMs ?: number ;
333339 } ;
334340} ;
335341
@@ -423,6 +429,7 @@ export class ReflagClient {
423429 private autoFeedbackInit : Promise < void > | undefined ;
424430 private readonly flagsClient : FlagsClient ;
425431 private readonly bulkQueue : BulkQueue | undefined ;
432+ private readonly handleBeforeUnload ?: ( ) => void ;
426433
427434 public readonly logger : Logger ;
428435
@@ -480,6 +487,14 @@ export class ReflagClient {
480487 } ,
481488 ) ;
482489 }
490+ if ( this . bulkQueue && ! IS_SERVER ) {
491+ this . handleBeforeUnload = ( ) => {
492+ void this . bulkQueue ?. flush ( ) ;
493+ } ;
494+ window . addEventListener ( "beforeunload" , this . handleBeforeUnload , {
495+ capture : true ,
496+ } ) ;
497+ }
483498
484499 const bulkQueue = this . bulkQueue ;
485500
@@ -590,6 +605,12 @@ export class ReflagClient {
590605 *
591606 **/
592607 async stop ( ) {
608+ if ( this . handleBeforeUnload && ! IS_SERVER ) {
609+ window . removeEventListener ( "beforeunload" , this . handleBeforeUnload , {
610+ capture : true ,
611+ } ) ;
612+ }
613+
593614 if ( this . bulkQueue ) {
594615 await this . bulkQueue . flush ( ) ;
595616 let remaining = await this . bulkQueue . size ( ) ;
0 commit comments