* Describe the bug*
Might just be me overseeing something but When using Gatsby together with Animate Pressence the page will jump to the top before starting the exit animation
* IMPORTANT: Provide a CodeSandbox reproduction of the bug*
https://codesandbox.io/s/sharp-ardinghelli-jw5f9
From another gatsby issue that was fixed but im using the same browser config with animating pressence as this one.
* Steps to reproduce*
Expected behavior
I think it麓s a Gatsby issue somehow but it would be nice if there was a solution to it not jumping to the top of the page before beginning to animate out.
Same problem with Next.JS
Edit: for Next as a workaround you can disable the scroll to top for links:
https://nextjs.org/docs/api-reference/next/link#disable-scrolling-to-the-top-of-the-page
and handle scrolling in the onExitComplete event on AnimatePresence
Sadly not a option with Gatsby Link as far as i know :/ but nice you found out for NextJS!
Try adding the following code to your gatsby-browser.js file:
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;
};
@michaeljblum That works like a charm! thank you appreciate the reply
Most helpful comment
Try adding the following code to your gatsby-browser.js file: