-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[using-page-transitions] Scrolls to top before animating #7921
Comments
Hi @b0gd4n, can you also provide the information with regards to package versions by running |
@kakadiadarpan here's the clip:
|
This behaviour can be seen on the |
Thanks for sharing the details and the video. We'll look into this. |
I think this has to do with something exports.shouldUpdateScroll = () => false |
@stefanprobst it def has something to do with that. |
I think might work
EDIT: scratch that - this does not work - still scrolls to top before fading out. I even tried 3000ms delay |
As a workaround try this: const transitionDelay = 250
exports.shouldUpdateScroll = () => false
exports.onRouteUpdate = () =>
window.setTimeout(() => window.scrollTo(0, 0), transitionDelay) |
@stefanprobst this kind of works, but on page nav it always goes to top (even when navigating back). The point of the |
@b0gd4n AFAIU what happens in const results = apiRunner(`shouldUpdateScroll`, {
prevRouterProps,
pathname,
savedScrollPositions: this._stateStorage
}) And then access them in shouldUpdateScroll like so: exports.shouldUpdateScroll = ({ pathname, savedScrollPositions }) => {
const pos = savedScrollPositions.read({ pathname })
// Update position
return false
} (3) Without any of that , for now the best I could think of is this: const transitionDelay = 250
exports.shouldUpdateScroll = ({ pathname }) => {
// // We use a temporary hack here, see #7758
if (window.__navigatingToLink) {
window.setTimeout(() => window.scrollTo(0, 0), transitionDelay)
} else {
const savedPosition = JSON.parse(
window.sessionStorage.getItem(`@@scroll|${pathname}`)
)
window.setTimeout(() => window.scrollTo(...savedPosition), transitionDelay)
}
return false
} Would be good to also check for initial render with |
@stefanprobst since #8061 got merged in what is the recommended way now to set a delay on the scroll position during the page transition? Is there example code anywhere? |
On the
using-page-transitions
example, the page scrolls to top just before fade-out animations starts.If you have a long page, and click a link to trigger a route change, it immediately scrolls to top of the current page, then the fade-out animation begins, then the new page loads in.
I see the
gatsby-react-router-scroll
is a gatsby dependency - is there a way to pass a timeout so you don't get that page flash?This behaviour can be checked here https://www.kaizen.co.uk/
The text was updated successfully, but these errors were encountered: