Skip to content

Commit

Permalink
Temp fix for scroll behavior problems
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Aug 30, 2018
1 parent 37161a2 commit 5f09cc3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/gatsby-link/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import React from "react"
import { Link, Location } from "@reach/router"
import { parsePath } from "gatsby"

// Temp hack while awaiting https://github.com/reach/router/issues/119
if (typeof window !== `undefined`) {
window.__navigatingToLink = false
}

export function withPrefix(path) {
return normalizePath(`${__PATH_PREFIX__}/${path}`)
}
Expand Down Expand Up @@ -151,6 +156,9 @@ class GatsbyLink extends React.Component {
}
}

// Temp hack while awaiting https://github.com/reach/router/issues/119
window.__navigatingToLink = true

// Make sure the necessary scripts and data are
// loaded before continuing.
navigate(prefixedTo, { state })
Expand Down
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
2 changes: 2 additions & 0 deletions packages/gatsby/cache-dir/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ 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
}
}

Expand Down

0 comments on commit 5f09cc3

Please sign in to comment.