Skip to content
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

Temp fix for scroll behavior problems #7758

Merged
merged 2 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this to

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be in

const navigate = (to, options) => {
rather than Link component to cover programmatic navigation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, and if it was moved there probably it should be in if (!option.replace) (not entirely sure here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oo right, programmatic nav, forgot about that. Will switch over.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and yeah, replacing shouldn't update the scroll


// 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure this will work everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for suspecting it wouldn't?

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