Skip to content

Commit

Permalink
Temp fix for scroll behavior problems (#7758)
Browse files Browse the repository at this point in the history
* Temp fix for scroll behavior problems

* Move navigation hacks to navigation.js so works for programmatic nav
  • Loading branch information
KyleAMathews authored Aug 30, 2018
1 parent 6199872 commit 4c676f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ class ScrollContext extends React.Component {

// The "scroll-behavior" package expects the "action" to be on the location
// object so let's copy it over.
if (!location.action) {
location.action = `push`

// Temp hack while awaiting https://github.com/reach/router/issues/119
if (window.__navigatingToLink) {
location.action = `PUSH`
} else {
location.action = `POP`
}

this.scrollBehavior.updateScroll(prevRouterProps, { history, location })
}

Expand Down
12 changes: 11 additions & 1 deletion packages/gatsby/cache-dir/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ const onPreRouteUpdate = location => {
const onRouteUpdate = location => {
if (!maybeRedirect(location.pathname)) {
apiRunner(`onRouteUpdate`, { location })
// Temp hack while awaiting https://github.com/reach/router/issues/119
window.__navigatingToLink = false
}
}

const navigate = (to, options) => {
const navigate = (to, options = {}) => {
// Temp hack while awaiting https://github.com/reach/router/issues/119
if (!options.replace) {
window.__navigatingToLink = true
}

let { pathname } = parsePath(to)
const redirect = redirectMap[pathname]

Expand Down Expand Up @@ -109,6 +116,9 @@ function shouldUpdateScroll(prevRouterProps, { location: { pathname } }) {
}

function init() {
// Temp hack while awaiting https://github.com/reach/router/issues/119
window.__navigatingToLink = false

setApiRunnerForLoader(apiRunner)
window.___loader = loader
window.___push = to => navigate(to, { replace: false })
Expand Down

0 comments on commit 4c676f5

Please sign in to comment.