OnReady function not loading properly

I have a dynamic page per product and sometimes it does not load properly. I do not think is a code issue since in the preview and live sometimes it works fine BUT randomly the product page might not load properly (sometimes even the image of the product does not change and the selection buttons also do not work). This can be fixed by refreshing the page several times but of course is not scalable at all.

EDIT: apparently is an issue with this part of the code:

w . onReady ( async () => {

if  (! wixStorage.session . getItem ( "refreshed" )) { 
    wixStorage.session . setItem ( "refreshed" ,  "true" ); 
    wixLocation . to ( wixLocation.url ); 
}  **else**  { 
    wixStorage.session . removeItem ( "refreshed" ); 
} 

const  currentItem  =  **await**  $w ( "#dynamicDataset" ). getCurrentItem (); 
city  =  currentItem.ciudadText . toLowerCase (); 
model  =  currentItem.modeloText . toLowerCase (); 

This is the error I get