From 36c9576609b9cd86cb06cca5b0afff078147b150 Mon Sep 17 00:00:00 2001 From: Nima Arefi Date: Mon, 29 Jun 2020 14:46:26 +0430 Subject: [PATCH 1/2] feat(after): change variable name --- packages/after.js/src/After.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/after.js/src/After.tsx b/packages/after.js/src/After.tsx index 16e1a9aa..6604534f 100644 --- a/packages/after.js/src/After.tsx +++ b/packages/after.js/src/After.tsx @@ -132,12 +132,12 @@ class Afterparty extends React.Component { const { location: currentLocation, transitionBehavior } = this.props; const initialData = this.prefetcherCache[currentLocation.pathname] || data; - const instantTransition = isInstantTransition(transitionBehavior) + const instantMode = isInstantTransition(transitionBehavior) // when we are in the instant mode we want to pass the right location prop // to the otherwise it will render previous matche component const location = - instantTransition + instantMode ? currentLocation : previousLocation || currentLocation; From c1fa60b3dacb70952e8a9e5f162e8d0ba29acab8 Mon Sep 17 00:00:00 2001 From: Nima Arefi Date: Mon, 29 Jun 2020 14:47:03 +0430 Subject: [PATCH 2/2] feat(after): fix scroll to top in instantMode --- packages/after.js/src/After.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/after.js/src/After.tsx b/packages/after.js/src/After.tsx index 6604534f..cefa8a69 100644 --- a/packages/after.js/src/After.tsx +++ b/packages/after.js/src/After.tsx @@ -77,6 +77,7 @@ class Afterparty extends React.Component { history, routes, data, + transitionBehavior, // we don't want to pass these // to loadInitialProps() match, @@ -87,6 +88,19 @@ class Afterparty extends React.Component { const { scrollToTop } = data.afterData; + const instantMode = isInstantTransition(transitionBehavior) + + // Only for page changes, prevent scroll up for anchor links + if ( + (prevState.currentLocation && + prevState.currentLocation.pathname) !== location.pathname && + // Only Scroll if scrollToTop is not false + scrollToTop.current === true && + instantMode === true + ) { + window.scrollTo(0, 0); + } + loadInitialProps(routes, location.pathname, { location, history, @@ -101,10 +115,12 @@ class Afterparty extends React.Component { (prevState.currentLocation && prevState.currentLocation.pathname) !== location.pathname && // Only Scroll if scrollToTop is not false - scrollToTop.current + scrollToTop.current === true && + instantMode === false ) { window.scrollTo(0, 0); } + this.setState({ previousLocation: null, data, isLoading: false }); }) .catch(e => {