-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -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}`) | ||||
} | ||||
|
@@ -151,6 +156,9 @@ class GatsbyLink extends React.Component { | |||
} | ||||
} | ||||
|
||||
// Temp hack while awaiting https://github.com/reach/router/issues/119 | ||||
window.__navigatingToLink = true | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be in
Link component to cover programmatic navigation
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, and if it was moved there probably it should be in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oo right, programmatic nav, forgot about that. Will switch over. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 }) | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure this will work everywhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 }) | ||
} | ||
|
||
|
There was a problem hiding this comment.
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
gatsby/packages/gatsby/cache-dir/navigation.js
Line 113 in 5f09cc3