You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been facing a browser navigation issue with the Snipcart script in a NextJS project. I created a minimal reproduction fork here: https://github.com/talhaguy/next-snipcart-store. The issue is as follows:
Replication Steps
Go to home page
Click on FAQ page link in nav
Once FAQ page is loaded, press browser back button
Expected
Page should go back again.
Actual
Page visually remains on the same one. The URL does change though.
After some debugging, I noticed the history state object is a little different on the landing page with and without Snipcart.
Although it does seem to be working fine now, it feels hacky. Is there a better way to handle this? Is this truly a conflict between NextJS routing and Snipcart routing?
Thank you,
Muhammad Talha
The text was updated successfully, but these errors were encountered:
Thanks, @colbyfayock - Just adding on here that I had to update the useResetHistory hook with the following since it was breaking on pages with dynamic slugs:
functionuseResetHistory(){constrouter=useRouter()useEffect(()=>{document.addEventListener("snipcart.ready",()=>{Snipcart.events.on('snipcart.initialized',(snipcartState)=>{// use `router.asPath` instead of `router.pathname`router.replace(router.asPath)});});},[])}
Hello!
I've been facing a browser navigation issue with the Snipcart script in a NextJS project. I created a minimal reproduction fork here: https://github.com/talhaguy/next-snipcart-store. The issue is as follows:
Replication Steps
Expected
Page should go back again.
Actual
Page visually remains on the same one. The URL does change though.
After some debugging, I noticed the history state object is a little different on the landing page with and without Snipcart.
history.state with Snipcart:
history.state without Snipcart:
I created a branch in the reproduction repo with a fix by replacing the landing page history state: https://github.com/talhaguy/next-snipcart-store/tree/fix. I am using the NextJS router to accomplish this:
Although it does seem to be working fine now, it feels hacky. Is there a better way to handle this? Is this truly a conflict between NextJS routing and Snipcart routing?
Thank you,
Muhammad Talha
The text was updated successfully, but these errors were encountered: