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

scrollBehavior doesn't work for initial route in Firefox #1585

Closed
hworld opened this issue Jul 11, 2017 · 9 comments · Fixed by #1586
Closed

scrollBehavior doesn't work for initial route in Firefox #1585

hworld opened this issue Jul 11, 2017 · 9 comments · Fixed by #1586
Labels

Comments

@hworld
Copy link
Contributor

hworld commented Jul 11, 2017

Version

2.7.0

Reproduction link

https://github.com/vuejs/vue-router/tree/dev/examples/scroll-behavior

Steps to reproduce

Sorry, because this requires history navigation I can't give too great of a link. This manifests itself in the scroll-behavior example of the vue-router repo, though.

Basically, open a new tab to the scroll behavior example: http://localhost:8080/scroll-behavior/bar

Scroll just a little bit down and click on the "bar" link. It will correctly scroll to the top again. When you press back it will stay at the top, though, and not go to the previous scroll. By the way, for me this doesn't manifest in Chrome. I believe they are doing their own scrolling by default for history navigation through this: https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration

Firefox should manifest the issue, though.

What is expected?

I expect it to be able to scroll properly even for initial route.

What is actually happening?

It doesn't scroll correctly.


The reason it happens is since the first request wasn't done through a pushState there is no state object stored. It needs the state object to store the scroll position.

This issue is probably known, however I think we may be able to fix it by doing a replaceState right away with a new state object, yeah?

@hworld
Copy link
Contributor Author

hworld commented Jul 23, 2017

hmm, maybe you can take a look at this @posva ? should be fairly straightforward i hope

@posva
Copy link
Member

posva commented Jul 23, 2017

Yes, sorry, I'll take a look

@posva posva added the bug label Jul 23, 2017
@posva posva changed the title scrollBehavior doesn't work for initial route scrollBehavior doesn't work for initial route in Firefox Jul 23, 2017
@posva
Copy link
Member

posva commented Jul 23, 2017

I'm really sorry for the delay, this could have been looked up the same day you made the issue and pr.
Thanks a lot 🙂

@hworld
Copy link
Contributor Author

hworld commented Jul 23, 2017

Thanks for taking a look at it! 🥇

@hworld
Copy link
Contributor Author

hworld commented Aug 16, 2017

Hey @posva Don't mean to be annoying, just curious if that was still planned on getting pulled in some time?

@posva
Copy link
Member

posva commented Aug 16, 2017

Don't worry, it's ok to ping people when it takes time 🙂
I'm waiting for the review of Evan, I pinged him again

@jafri
Copy link

jafri commented Aug 23, 2018

Still an issue, scrollBehavior doesn't work for initial route in latest chrome

@ghost
Copy link

ghost commented Sep 20, 2018

Hi, the fix associated works probably well for firefox, but fails for ie9.

According to the rest of the code, the history.replaceState should be encapsulated in a try catch, falling back to do nothing probably, in the catch.

May a raise a PR about this?

@posva
Copy link
Member

posva commented Sep 24, 2018

it was already fixed but not released yet (#1835)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants