Uncaught (in promise) Lightbox is open

I’m opening a lightbox. It opened and works fine, but the browser console shows this error: “Uncaught (in promise) Lightbox is open”.

I tried to keep it simple: I’ve made an empty lightbox, called it with and without “.then…”. Still I get this error.

wixWindow.openLightbox("try1");
wixWindow.openLightbox("try1")
        .then( (data) => {
               console.log ("hi");
        } );

The “try1” lightbox is empty, does nothing.

What causes the error?

tnx

Please post the URL of your site and indicate what page.

I got it: that’s because smoehow it tries to open it twice (and the error says that the lightbox is already open). I have no idea why.

I solved it with adding a flag before:

let twice = false // global variable
        
if (twice === false){
        twice = wixWindow.openLightbox ("myLightBox")
        ...

So how is it being called? I can’t see how it would be opened twice.

It is called for the first time because twice === false. Then when it tries to be called again (I don’t know why), it won’t, because ‘twice’ gets the promise from wixWindow.openLightbox and it is not ‘false’ anymore…

I know it has been called twice, because I put a console.log inside the onClick function, and indeed it displayed twice…

Go figure it out :wink:

@avtsy I’d like to figure it out. Please share the code, or post your site’s URL (and page) so I can take a look.

@yisrael-wix A few months later, I could be facing the same problem. Would you check the very end of this new thread please?

@gemats
Issue already eliminated :grin::laughing::wink:

I had the same error for a different reason.

I was opening my register lightbox directly from a button on my login lightbox.

To redirect the user to the register lightbox successfully I pretty much had to close the login lightbox with data saying “Open register lightbox” that was received by the original page.

i.e. here is my login button callback:

export function logIn_onClick ( ){
let userId ;
let isLoggedIn ;
let userRole ;
let userEmail ;

**if**  ( wixUsers . currentUser . loggedIn ){ 
    wixUsers . logout (); 
    $w ( '#logIn' ). label  =  'Log In' ; 
    $w ( '#myAccount' ). hide (); 
    $w ( '#tutorProfile' ). hide (). then (() =>  wixLocation . to ( "/" )) 
    
} 
**else**  { 
    wixWindow . openLightbox ( "LOGIN" ) 
    . then (( data ) => { 
        console . log ( "Data received from login" ,  data ); 
        **if**  ( data . loginSuccessful ) { 
            wixData . query ( "CustomMembers" ). eq ( "userId" ,  wixUsers . currentUser . id ). find () 
            . then (( results ) => { 
                $w ( "#myAccount" ). show (); 
                $w ( "#tutorProfile" ). show (); 
                
                // if (results.items.length === 1) { 
                //  userRole = results.items[0].role; 
                //  console.log("User role post login", userRole); 
                //  if (userRole === "Customer") $w("#myAccount").show(); 
                //  else if (userRole === "Tutor" || userRole === "Admin") { 
                //      $w("#myAccount").show(); 
                //      $w("#tutorProfile").show(); 
                //  } 
                // } else console.log("Query result lenght neq 1", results); 
            }) 
        }  **else if**  ( data . registerUser ) { 
            wixWindow . openLightbox ( "REGISTER" ,  data . context ) 
            . then (( registerData ) => { 
                console . log ( "Register closed succesfully" ); 
            }) 
        } 
    }) 
} 

}