Skip to content

Scroll position lost on pop state (when clicking browser back/forward buttons) #11

@blimpmason

Description

@blimpmason

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions