@@ -389,25 +389,27 @@ try {
389389 // No Storybook
390390}
391391
392- const onDestroyCallbacks = new Set < ( ) => void > ( ) ;
393- const beforeNavigateCallbacks = new Set < ( nav : BeforeNavigate ) => Promise < void > > ( ) ;
394- let lifeCycleHandlersInited = false ;
392+ const lifeCycleCallbacks = {
393+ onDestroy : new Set < ( ) => void > ( ) ,
394+ beforeNavigate : new Set < ( nav : BeforeNavigate ) => Promise < void > > ( )
395+ }
396+ let componentInitialized = false ;
395397function initLifeCycleCallbacks ( ) {
396- if ( lifeCycleHandlersInited ) return ;
397- lifeCycleHandlersInited = true ;
398+ if ( componentInitialized ) return ;
399+ componentInitialized = true ;
398400
399401 onDestroy ( ( ) => {
400- for ( const callback of onDestroyCallbacks ) {
402+ for ( const callback of lifeCycleCallbacks . onDestroy ) {
401403 callback ( ) ;
402404 }
403- onDestroyCallbacks . clear ( ) ;
405+ lifeCycleCallbacks . onDestroy . clear ( ) ;
404406 } ) ;
405407
406408 beforeNavigate ( ( nav : BeforeNavigate ) => {
407- for ( const callback of beforeNavigateCallbacks ) {
409+ for ( const callback of lifeCycleCallbacks . beforeNavigate ) {
408410 callback ( nav ) ;
409411 }
410- beforeNavigateCallbacks . clear ( ) ;
412+ lifeCycleCallbacks . beforeNavigate . clear ( ) ;
411413 } ) ;
412414}
413415
@@ -548,7 +550,7 @@ export function superForm<
548550
549551 ///// From here, form is properly initialized /////
550552
551- onDestroyCallbacks . add ( ( ) => {
553+ lifeCycleCallbacks . onDestroy . add ( ( ) => {
552554 Unsubscriptions_unsubscribe ( ) ;
553555 NextChange_clear ( ) ;
554556 EnhancedForm_destroy ( ) ;
@@ -1380,7 +1382,7 @@ export function superForm<
13801382 // Tainted check
13811383 const defaultMessage = 'Leave page? Changes that you made may not be saved.' ;
13821384 let forceRedirection = false ;
1383- beforeNavigateCallbacks . add ( async ( nav : BeforeNavigate ) => {
1385+ lifeCycleCallbacks . beforeNavigate . add ( async ( nav : BeforeNavigate ) => {
13841386 if ( options . taintedMessage && ! Data . submitting && ! forceRedirection ) {
13851387 if ( Tainted_isTainted ( ) ) {
13861388 const { taintedMessage } = options ;
0 commit comments