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

Add example for gatsby-browser.js API shouldUpdateScroll #3857

Closed
wants to merge 2 commits into from
Closed

Add example for gatsby-browser.js API shouldUpdateScroll #3857

wants to merge 2 commits into from

Conversation

amslezak
Copy link
Contributor

@amslezak amslezak commented Feb 4, 2018

No description provided.

@gatsbybot
Copy link
Collaborator

gatsbybot commented Feb 4, 2018

Deploy preview for gatsbygram ready!

Built with commit 3154a9d

https://deploy-preview-3857--gatsbygram.netlify.com

@@ -35,6 +35,11 @@ exports.onRouteUpdate = true
* @param {object} $0
* @param {object} $0.prevRouterProps The previous state of the router before the route change.
* @param {object} $0.pathname The new pathname
* @example
* exports.shouldUpdateScroll = (prevRouterProps, pathname) => {
* window.scrollTo(0, 0) // upon navigation, scroll to top of page
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious what the use case for doing this would be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For my particular use-case, I wanted it so when navlinks clicked always start at the top of the page. By default, they start off at the last scrolled position of the page. This example overrides that behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you try upgrading to the latest Gatsby? There was a bug that was causing problems with scrolling that I fixed in #3775

It sounds like you were just running into that bug.

I'd love an example for this API but it should be a realistic one — not one that works around a bug :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood! I'll remove my workaround, and then test. If I come up with a better example, I will absolutely submit. Thanks for the update, Kyle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just confirming you fixed the issue I was having with your patch.

@@ -152,6 +152,7 @@ Websites built with Gatsby:
* [ERC dEX](https://ercdex.com)
* [iContract Blog](https://blog.icontract.co.uk)
* [Dona Rita](https://donarita.co.uk) ([source](https://github.com/peduarte/dona-rita-website))
* [Andy Slezak](https://www.aslezak.com) ([source](https://github.com/amslezak))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you do this in a separate PR? Thanks!

@amslezak
Copy link
Contributor Author

amslezak commented Feb 7, 2018

closing this issue, and opening separate PRs.

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.

None yet

3 participants