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

Changing hash in URL causes getInitialProps to be re-fired #2825

Closed
1 task done
ldthorne opened this issue Aug 21, 2017 · 10 comments · Fixed by #7255
Closed
1 task done

Changing hash in URL causes getInitialProps to be re-fired #2825

ldthorne opened this issue Aug 21, 2017 · 10 comments · Fixed by #7255
Assignees

Comments

@ldthorne
Copy link
Contributor

ldthorne commented Aug 21, 2017

Changing the hash in the URL causes getInitialProps to be fired, which I think should've been fixed in this PR. See the following example repo: https://github.com/ldthorne/nextjs-back-reproduction.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

If the user clicks the go somewhere link that leads to an anchor -- which will add a hash to the url -- and then clicks the back button, getInitialProps should not be called.

Current Behavior

If the user clicks the go somewhere link that leads to an anchor -- which will add a hash to the url -- and then clicks the back button, getInitialProps is called.

Steps to Reproduce (for bugs)

  1. Clone repo: https://github.com/ldthorne/nextjs-back-reproduction.
  2. yarn.
  3. Open dev tools.
  4. Click the go somewhere link. Notice that nothing is logged.
  5. Click the browser's back button. Notice that getInitialProps is logged.

Your Environment

Tech Version
next 3.0.6
node 8.1.2
OS macOS 10.12.6
browser All
@ldthorne
Copy link
Contributor Author

@arunoda it seems like you might have experience with this (based on the PR you opened) -- any thoughts on this issue?

@timneutkens
Copy link
Member

So the issue here is that the hash change only checks as and you've not provided it. I guess this is kind of a bug 🤔 @arunoda will be able to give a definitive answer on how to fix it, since he wrote it 😄

@arunoda
Copy link
Contributor

arunoda commented Aug 30, 2017

@ldthorne I'm looking into this today.

@ldthorne
Copy link
Contributor Author

ldthorne commented Sep 5, 2017

Hi @arunoda, any chance you've had any luck tracking down the issue?

@coluccini
Copy link
Contributor

If you don't want to use route in anyway, I think has more sense to just use <a href="#somewhere">somewhere</a> instead using the Link component. Maybe your real use case has some other implication?

@ldthorne
Copy link
Contributor Author

Thanks for the suggestion, @coluccini. I tried that in my example repo, but it still fires getInitialProps.

@coluccini
Copy link
Contributor

Ups, I didn't read that this was happening when clicking back button. Sorry.

@ldthorne
Copy link
Contributor Author

No worries. Thanks for your help!

@ldthorne
Copy link
Contributor Author

Hi @arunoda, any chance you have any updates?

@michaeljonathanblack
Copy link

michaeljonathanblack commented Oct 5, 2018

I'm looking into this now and I think I have a fix.

It appears to be that this.asPath was not getting set inside the Router hash change event, so the function which checks whether or not a hash navigation has occurred was using incorrect data.

I think I might take a look at a bunch of hash-navigation related bugs and see if I can make PRs for a them while I'm digging around in here...

michaeljonathanblack added a commit to michaeljonathanblack/next.js that referenced this issue Oct 24, 2018
michaeljonathanblack pushed a commit to michaeljonathanblack/next.js that referenced this issue Oct 26, 2018
michaeljonathanblack added a commit to michaeljonathanblack/next.js that referenced this issue Oct 30, 2018
michaeljonathanblack added a commit to michaeljonathanblack/next.js that referenced this issue Oct 30, 2018
michaeljonathanblack pushed a commit to michaeljonathanblack/next.js that referenced this issue Oct 30, 2018
michaeljonathanblack added a commit to michaeljonathanblack/next.js that referenced this issue Nov 5, 2018
michaeljonathanblack added a commit to michaeljonathanblack/next.js that referenced this issue Nov 5, 2018
michaeljonathanblack pushed a commit to michaeljonathanblack/next.js that referenced this issue Nov 16, 2018
timneutkens added a commit to michaeljonathanblack/next.js that referenced this issue Nov 18, 2018
michaeljonathanblack added a commit to michaeljonathanblack/next.js that referenced this issue Nov 20, 2018
…ps' of github.com:mherodev/next.js into bugfix/vercel#2825-changing-hash-triggers-getInitialProps
michaeljonathanblack added a commit to michaeljonathanblack/next.js that referenced this issue Nov 21, 2018
michaeljonathanblack added a commit to michaeljonathanblack/next.js that referenced this issue Nov 21, 2018
michaeljonathanblack pushed a commit to michaeljonathanblack/next.js that referenced this issue Nov 21, 2018
michaeljonathanblack pushed a commit to michaeljonathanblack/next.js that referenced this issue Dec 10, 2018
michaeljonathanblack pushed a commit to michaeljonathanblack/next.js that referenced this issue Jan 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2020
ForsakenHarmony pushed a commit that referenced this issue Jul 25, 2024
### Description

This update includes an improvement of `@swc/helpers`, so we need to
update `@swc/helpers` too when updating next-swc.

### Testing Instructions

Fix WEB-744
Fix WEB-859

---

 - Fixes #2825.
 - Fixes #4092.
ForsakenHarmony pushed a commit that referenced this issue Jul 29, 2024
### Description

This update includes an improvement of `@swc/helpers`, so we need to
update `@swc/helpers` too when updating next-swc.

### Testing Instructions

Fix WEB-744
Fix WEB-859

---

 - Fixes #2825.
 - Fixes #4092.
ForsakenHarmony pushed a commit that referenced this issue Aug 1, 2024
### Description

This update includes an improvement of `@swc/helpers`, so we need to
update `@swc/helpers` too when updating next-swc.

### Testing Instructions

Fix WEB-744
Fix WEB-859

---

 - Fixes #2825.
 - Fixes #4092.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
6 participants