-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[added] preserveScrollPosition Route/Routes props #129
Conversation
} | ||
}; | ||
|
||
module.exports = ScrollsOnTransition; |
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 initially put this on willTransitionTo
, but the entire issue arises when the previous page has long content, so it seems to make sense to do it on the page that causes the problem you want to mitigate, rather than on every potential victim.
I am hesitant to start dabbling in inheritance/object composition in the router. I wish React dealt with static methods like instance methods. @spicyj is there some way that React handles mixins with statics? |
It looks like duplicate statics keys currently create chained functions when both properties are functions, but this behavior doesn't make a ton of sense to me – I'd expect it to give an error. Filed facebook/react#1947. |
@spicyj Thanks for digging in further. I'd expect it to give an error too. Sounds like we should probably just use a |
I'm going to need some convincing to put it on the |
Ok. Then put it in |
If it goes on |
do not be fooled by my avatar, I am a real person who uses github. |
@spicyj this is what happens for life-cycle hooks though, I actually like that they do it for statics, its the exact behavior I want/expected here :) I say we merge this and if react ever changes the behavior of static mixin methods, then we do something else. |
I know we do it for lifecycle methods, but that's partly because those don't return a value (shouldComponentUpdate isn't merged). We can talk about if the current behavior is more desirable, but I believe it's a mistake and was intended to throw an error. |
Made it a Route and Routes property. Switched it to scrolling on transition to. It is hard to think about use-cases that don't want to scroll so maybe I'm wrong. I say we ship this and if we're wrong, switch it or add two options, |
return; | ||
|
||
window.scrollTo(0, 0); | ||
} |
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 had this stuff in one conditional, but I feel like this reads nicer.
Looks good! 👍 |
[added] preserveScrollPosition Route/Routes props
I didn't test this yet but if it doesn't already, we should make this restore your previous scroll position properly when pressing back in your browser. |
Ah! I thought if that but forgot to add it Sent from my iPhone
|
Ahhh, works great guys! Was painless to incorporate and looks really good. Felt so good ripping out my scrollTo code. |
When a page’s content is long and you transition
to a new route, the scroll position persists
and its super dumb.
This mixin goes on a route handler that you know
has long content and scrolls the window up when
you leave the page.
Not a bad idea to put this on every route handler
closes #121