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 position lost on pop state (when clicking browser back/forward buttons) #11

Open
blimpmason opened this issue Oct 2, 2020 · 3 comments
Labels
question Further information is requested

Comments

@blimpmason
Copy link

blimpmason commented Oct 2, 2020

Hey @ryanwiemer — I've been using bits of your code from this example to implement page transitions on my Gatsby projects and it works great!

I've noticed in the last few months is that scroll restoration no longer works on popstate, despite this logic:

export const shouldUpdateScroll = ({
routerProps: { location },
getSavedScrollPosition
}) => {
if (location.action === "PUSH") {
window.setTimeout(() => window.scrollTo(0, 0), transitionDelay);
} else {
const savedPosition = getSavedScrollPosition(location);
window.setTimeout(
() => window.scrollTo(...(savedPosition || [0, 0])),
transitionDelay
);
}
return false;
};

I was wondering if you'd come across that issue and had any thoughts on a workaround.

Possibly related to this issue: gatsbyjs/gatsby#23842 ?

@blimpmason
Copy link
Author

When I console.log(savedPosition) within the else statement, I get 0, though I see all the scroll position entries saved in local storage.

@ryanwiemer
Copy link
Owner

@blimpmason was this ever fixed on Gatsby's side? This seems like an upstream issue that Gatsby needs to resolve.

@ryanwiemer ryanwiemer added the question Further information is requested label Nov 19, 2020
@blimpmason
Copy link
Author

@ryanwiemer you're absolutely right, and I submitted an issue to Gatsby in October along with minimal reproduction demos and repos. The issue been acknowledged and I think there's an outstanding pull request that addresses it: gatsbyjs/gatsby#27349

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

No branches or pull requests

2 participants