-
Notifications
You must be signed in to change notification settings - Fork 58
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 position is restored when not needed #215
Comments
That's a good catch. The issue here is that the initial location doesn't get supplemented with a randomly-generated key, as we didn't want to trigger an immediate navigation action on page load. Not quite sure how to deal with this one. That said, this isn't specific to Found. The same thing will happen on e.g. most sites that use anything like this logic for determining page key, including Gatsby sites. You can see this behavior on e.g. https://reactjs.org. cc @KyleAMathews @jquense – older versions of React Router actually would immediately redirect to a version of the page with a random |
@taion Yeah, I recall that in For the current situation, I was thinking about clearing all window.onload = function onPageLoad() {
forEach((key) => {
if (key.indexOf('@@scroll|') === 0) {
sessionStorage.removeItem(key)
}
}
}
function forEach(func) {
let i = 0
while (i < sessionStorage.length) {
const key = sessionStorage.key(i)
func(key)
i++
}
} |
That's not quite the same, though. To emulate native browser scroll behavior, you do want to preserve scroll position if someone reloads the page. |
@taion Aaah, I see. I wonder what's the point of preserving scroll position in browsers when a user reloads a page though. What's the rationale, the motivation. Whatever. |
And to be clear, we do still attach keys on navigation to locations after the first. But we don't do this for the first location because it would require triggering a history action to get it stamped on. |
Whats wrong with storing a random key on each location entry? That makes perfect sense to me - a key to identify each one so that even if the URL is the same, there is something to distinguish 2 separate location entries that should not share the same scroll position. Hard to see how this library could work properly if the locations provided to it are not unique. |
Farce adds unique keys to all locations that it generates. However, for the initial page load, I'm not aware of a way to update the location state. Old versions of |
What kind of bugs did it cause? |
I honestly can't remember any more. It was enough that they took it out in history v4, though. |
I found a bug in scroll position restoration in
found
library.The scroll position is stored in Session storage:
where
/vg
is the page path.If a user opens a page, then goes to the URL bar and enters another page URL, then goes to the URL bar again and enters the initial page URL — the page loads and the scroll is at where the user left it initially, not at the top of the page, because Session storage still has that entry. And the entry has no random-generated hash or anything.
The text was updated successfully, but these errors were encountered: