src/effects/HistoryListener.js
/*
Keep track of where we scroll to on a page and if we return to that page restore
the position. Since Izzy is a SPA app the standard browser scroll restoration
doesn't work but in the future browsers will hopefully do this for us (Chrome
already). But until then we've got to do it manually.
*/
Keep track of where we scroll to on a page and if we return to that page restore
the position. Since Izzy is a SPA app the standard browser scroll restoration
doesn't work but in the future browsers will hopefully do this for us (Chrome
already). But until then we've got to do it manually.
Keep track of where we scroll to on a page and if we return to that page restore the position . Since Izzy is a SPA app the standard browser scroll restoration doesn ' t work but in the future browsers will hopefully do this for us ( Chrome already ) . But until then we ' ve got to do it manually .
function registerScrollRestoration(location) {
    if (history.scrollRestoration) {
        history.scrollRestoration = "manual";
    }
    const sessionKey = `scrollPosition-${location.key}`
    const sessionValue = sessionStorage.getItem(sessionKey)
    if (sessionValue !== null) {
        waitTillPageLoaded().then(
            () => window.scrollTo(0, Number(sessionValue))
        ).catch()
    } else {
        window.scrollTo(0, 0);
    }
    function handleScroll() {
        sessionStorage.setItem(sessionKey, window.scrollY)
    }
    document.addEventListener("scroll", handleScroll)
    return () => document.removeEventListener("scroll", handleScroll);
}
function registerScrollRestoration ( location ) { if ( history . scrollRestoration ) { history . scrollRestoration = "manual" ; } const sessionKey = ` ${ location . key } ` const sessionValue = sessionStorage . getItem ( sessionKey ) if ( sessionValue !== null ) { waitTillPageLoaded ( ) . then ( ( ) => window . scrollTo ( 0 , Number ( sessionValue ) ) ) . catch ( ) } else { window . scrollTo ( 0 , 0 ) ; } function handleScroll ( ) { sessionStorage . setItem ( sessionKey , window . scrollY ) } document . addEventListener ( "scroll" , handleScroll ) return ( ) => document . removeEventListener ( "scroll" , handleScroll ) ; }
Keep track of where we scroll to on a page and if we return to that page restore
the position.
Keep track of where we scroll to on a page and if we return to that page restore the position .