Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser back button is not working #1

Closed
talhaguy opened this issue Nov 19, 2020 · 4 comments
Closed

Browser back button is not working #1

talhaguy opened this issue Nov 19, 2020 · 4 comments
Labels
bug Something isn't working pts: 1

Comments

@talhaguy
Copy link
Owner

talhaguy commented Nov 19, 2020

Replication Steps

  1. Go to home page
  2. Click on any link
  3. Click on another link
  4. Press browser back button
  5. See the page go back
  6. Click back button again

Expected
Page should go back again.

Actual
Page visually remains on the same one. The URL does change though.

@talhaguy
Copy link
Owner Author

Appears to be happening after commit ccb7e1d. Commit after this, 18369ef, is the one in which Snipcart was added. Snipcart may be messing with the routing.

@talhaguy talhaguy added the bug Something isn't working label Nov 19, 2020
@talhaguy
Copy link
Owner Author

Reached out to Snipcart support. Created minimal repo with reproduction for them: https://github.com/talhaguy/next-snipcart-store

@talhaguy
Copy link
Owner Author

Haven't heard anything yet from Snipcart. I have opened an issue in their NextJS sample repo: snipcart/next-snipcart-store#1

@talhaguy
Copy link
Owner Author

I noticed that the history.state object a different initial landing page value in the case that you use Snipcart and in the case that you do not:

With:
with-snipcart

Without:
wo-snipcart

If the history state is the issue, this sample code seems to resolve it:

// _app.js

import { useEffect } from 'react';
import { useRouter } from 'next/router'

function useResetHistory() {
  const router = useRouter()

  useEffect(() => {
    document.addEventListener("snipcart.ready", () => {
      Snipcart.events.on('snipcart.initialized', (snipcartState) => {
        router.replace(router.pathname)
      });
    });
  }, [])
}

function MyApp({ Component, pageProps }) {
  useResetHistory()

  return <Component {...pageProps} />
}

export default MyApp

talhaguy added a commit that referenced this issue Nov 26, 2020
…ton not working for first page - closes issue #1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pts: 1
Projects
None yet
Development

No branches or pull requests

1 participant