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

fix(gatsby-remark-autolink-headers): use shouldUpdateScroll api and not onRouteUpdate #9657

Merged
merged 2 commits into from
Nov 2, 2018

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Nov 2, 2018

right now autolink-headers scroll is battling with scrollbehaviour and which should handle scroll to #elementId. This allow autolink-headers plugin to hook into scrollbehaviour to override default behaviour.

Potential problems: shouldUpdateScroll is API that handles only one instance of this hook, so using it in autolink-headers plugin will discard results of this hook in user code (if it's used there)

closes #9638

window.scrollTo(0, offset - offsetY)
}
const getTargetOffset = hash => {
const id = window.decodeURI(window.location.hash.replace(`#`, ``))
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be missing something – but shouldn't this be hash instead of window.location.hash here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems reasonable! window.location.hash is already being passed here, so seems like you're right!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thanks!

Copy link
Contributor

@fk fk left a comment

Choose a reason for hiding this comment

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

Haven't looked into the code changes (and probably wouldn't understand much of what's going on ;-)), but can confirm that this fixes #9638 for www! 🎉 💜

Another @pieh slam dunk! 🏀 💯 ✨ 😅

@DSchau
Copy link
Contributor

DSchau commented Nov 2, 2018

Also @pieh you're probably aware, but it seems like that pathPrefix test has one flaky test that sometimes fails with:

CypressError: Timed out retrying: expected 'blank' to equal '/blog/'

Definitely unrelated to this PR, I'd think.

@pieh pieh merged commit 390803c into gatsbyjs:master Nov 2, 2018
@pieh pieh deleted the autolink-scroll-battle branch November 2, 2018 15:25
jayphelps added a commit to eclipse-iofog/iofog.org that referenced this pull request Nov 14, 2018
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this pull request Jan 22, 2019
…ot onRouteUpdate (gatsbyjs#9657)

* use shouldUpdateScroll api to not battle with builtin scrollbehaviour on scroll handling

* use passed hash, doh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[www] Tutorial sidebar links don't correctly jump to referenced element
4 participants