Cart overlay does not appear always / button not working

Snipcart cart overlay appears normally the first time, but if I navigate away and return, it’s not working until page refresh. Next.js app integration deployed on netlify. Console shows error

snipcart.js:51 The #snipcart div was removed from the document. This may happen when a frontend library is used to render the div. You should only render it once, or it might prevent the cart from working.
(anonymous) @ snipcart.js:51
snipcart.js:51 Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: “/cart”.

Moving snipcart id and data-api-key directly into script tag solves the problem. In contrast to this official snipcart and next app integration guide Next.js E-Commerce SPA Tutorial for Developers [Live Example] - Snipcart. (just an example, not passing key as env):

<Script
        src="https://cdn.snipcart.com/themes/v3.2.0/default/snipcart.js"
        hidden
        id="snipcart"
        data-api-key="demokey"
      ></Script>


      {/* <div
        hidden
        id="snipcart"
        data-api-key="demokey"
      ></div> */}

This hasn’t worked for me :frowning: The same error as above, I installed the code on my Layout component which is wrapped around all other pages so that I can display the value of the cart in the nav bar.