Multi-state box rendering issue ?

Hi everyone, I am suspecting that the rendering flow of the multi state box might be a little buggy. Here is the reason why :

$w.onReady(async function () {
     $w('#statebox').changeState("1") // Does not change anything
}

BUT

$w.onReady(async function () {
      setTimeout(() => {
                 $w('#statebox').changeState("1") // Actually changes the state if I wait 4 seconds
      }, 4000);
 }
 

I tried multiple tricks such as while loops , working with wixWindow.rendering.env or $w(‘#statebox’).rendered and other funny things, however nothing seems to be working.

Any idea ?

Thank you !

Why are you trying to render the state upon page ready? Why not just rearrange the order of the states via the settings so that “1” automatically renders first without any code at all?

Actually, I need to change the state on ready if the user is currently logged in, because logged-in user don’t need to see the first state