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

scroll on browser back button click #3663

Closed
wants to merge 1 commit into from

Conversation

vicky1999
Copy link
Contributor

@vicky1999 vicky1999 commented Feb 1, 2022

solves - #3621 and maybe #3636

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

Video Test:

Issue-.3621.mov

@changeset-bot
Copy link

changeset-bot bot commented Feb 1, 2022

⚠️ No Changeset found

Latest commit: 119203e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link

netlify bot commented Feb 1, 2022

✔️ Deploy Preview for kit-demo canceled.

🔨 Explore the source changes: 119203e

🔍 Inspect the deploy log: https://app.netlify.com/sites/kit-demo/deploys/61f983daf534600007dac983

@vicky1999 vicky1999 changed the title scroll on browser back click scroll on browser back button click Feb 2, 2022
@benmccann
Copy link
Member

Can you explain how you came to this solution and why you are making this change?

@vicky1999
Copy link
Contributor Author

vicky1999 commented Feb 3, 2022

@benmccann, when I tried to navigate to a hash and come back using back button, it didn't worked at first. but, at the second time, it worked. but, without scrolling. so, I thought that this problem is due to history. Then I saw this issue - #3636 and then found that, the history is being recorded twice.

Then, I looked into the code and found that, when using pushState, the history is recorded twice and the issue occurs ( #3636 ). So, I tried replaceState to replace the history entry. when using replaceState, it is working fine. I can be able to go back and forward and each time I tried, the page is scrolled to the correct position.

@vicky1999
Copy link
Contributor Author

vicky1999 commented Feb 5, 2022

@benmccann I have tested the approach. and it seems working. please let me know if there's any other way to resolve the issue.

@bluwy
Copy link
Member

bluwy commented Feb 8, 2022

I think there's a bigger issue with the behavour now, that somewhere in the code pushState is being called twice. With this PR, we're only making the first pushState a replaceState so we're pushing a new history entry once through the second pushState, and I dont think this is the right solution. We should find out where the second pushState happens and prevent that. Or maybe it's safe to remove the first pushState.

Maybe this was already discussed before and I missed it. But historically when we call the setTimeout pushState line, no other pushState is called later.

(I haven't looked deep into the behaviour yet)

@benmccann
Copy link
Member

Yes, I agree this is not the right solution, so I'm going to go ahead and close this. If you can point out on the issues where the two calls happen that may help us in designing a better solution

@benmccann benmccann closed this Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants