You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1- scroll down a long page
2- click a link - page 2 will be correctly scrolled to the top
3- click Back
4- click the same or any other link without scrolling
5- observe the new page is not scrolled to the top
If after Step 3, a scroll of any distance is performed, the bug does not occur.
I can confirm this happens. On latest Safari and Chome 46 as well. My reproduction steps:
Scroll down on a long page
pushState (react-router) to the next one
window might not be scrolled up at this point
go back (either through pushState or back button)
window might or might not be scrolled up
The behaviour is super weird. I've tried increasing the timeout to 500ms and that seems to solve it. Chrome's manual scrollRestoration seems to be broken given that it's definitely restoring the scroll position. However, it doesn't work with Safari either.
useScrollToTop seems to not be working on all pushes/replaces either. After triggering the pop bugs, and then "moving forwards" to previously visited pages (using history.pushState) it seems to be scrolling down to previous positions again.
Well, Safari doesn't support scrollRestoration at all, so nothing I can do there. Definitely weird that Chrome scrolls you up even with scrollRestoration disabled, though.
How many of these bugs were present with RR 0.13? It's possible this one is just unfixable for now.
We used ignoreScrollBehavior on the one route this is causing issues on previously. I hadn't heard any complaints on any browser, which is why I assumed it works on Safari. Might be wrong. :-)
We had no issues at all on RR 0.13. It is possible that I'm using it wrong. This bug is on my list of things to look more at. It occurred during a ridiculous big feature called upgrade to React 0.14 and react-router@1.0.0 😁 I'll try and get back to you with more details later on, hopefully even a fix.
I confess I never actually got scroll-behaviour integrated. I first used a snippet of code posted in one of the comments that precursed the creation of this package, and it worked more-or-less. When scroll-behaviour came into existence I tried to integrate it but had problems. I was going to ask for help/docs but ran out of time, so I stuck with the original hack - until a big package update broke the build and I had to look at it again. I again tried to integrate scroll-behavior but still had problems (this is probably just a documentation thing), and in the end I came up with a different (very simple) that seemed to do the job for me.
I was wondering, @taion et. al, what do you think about this approach?
import createHistory from 'history/lib/createBrowserHistory'
const history = createHistory();
history.listen(function(loc) {
// Don't scroll to top if user presses back
// - if (loc.action === 'POP' || loc.action === 'REPLACE') is an option
if (loc.action === 'POP') {
return;
}
// Allow the client to control scroll-to-top using location.state
if (loc.state && loc.state.scroll !== undefined && !loc.state.scroll) {
return;
}
// 200ms delay hack (for Firefox?)
setTimeout(() => {
window.scrollTo(0, 0);
}, 200);
});
module.exports = history;
It is used like this:
var history = require('history');
var C = React.createClass({
mixins: [ History ],
buttonClicked: function() {
// Prevent scroll-to-top in an event handler:
this.history.replaceState({ scroll: false }, '/');
},
render: function() {
return (
// Prevent scroll-to-top with a <Link>:
<Link to='/' state={{ scroll: false }}>
},
});
// ...
<Router history={history}>
<Route ...
Activity
taion commentedon Nov 13, 2015
Thanks for filing this! I don't have anything remotely like a solution right now, but it's good to track this - it's definitely a problem.
taion commentedon Nov 13, 2015
What version of Chrome are you on? This might just be fixed on Chrome 46+ now.
LDMFD commentedon Nov 13, 2015
Negative on 46.0.2490.86 (64-bit) (up-to-date)
mull commentedon Nov 16, 2015
I can confirm this happens. On latest Safari and Chome 46 as well. My reproduction steps:
The behaviour is super weird. I've tried increasing the timeout to 500ms and that seems to solve it. Chrome's manual scrollRestoration seems to be broken given that it's definitely restoring the scroll position. However, it doesn't work with Safari either.
useScrollToTop
seems to not be working on all pushes/replaces either. After triggering the pop bugs, and then "moving forwards" to previously visited pages (using history.pushState) it seems to be scrolling down to previous positions again.taion commentedon Nov 16, 2015
Well, Safari doesn't support scrollRestoration at all, so nothing I can do there. Definitely weird that Chrome scrolls you up even with scrollRestoration disabled, though.
How many of these bugs were present with RR 0.13? It's possible this one is just unfixable for now.
mull commentedon Nov 16, 2015
We used
ignoreScrollBehavior
on the one route this is causing issues on previously. I hadn't heard any complaints on any browser, which is why I assumed it works on Safari. Might be wrong. :-)We had no issues at all on RR 0.13. It is possible that I'm using it wrong. This bug is on my list of things to look more at. It occurred during a ridiculous big feature called upgrade to React 0.14 and react-router@1.0.0 😁 I'll try and get back to you with more details later on, hopefully even a fix.
mmahalwy commentedon Jan 21, 2016
@cachvico any update on this? I am experiencing this too
LDMFD commentedon Jan 21, 2016
I confess I never actually got scroll-behaviour integrated. I first used a snippet of code posted in one of the comments that precursed the creation of this package, and it worked more-or-less. When scroll-behaviour came into existence I tried to integrate it but had problems. I was going to ask for help/docs but ran out of time, so I stuck with the original hack - until a big package update broke the build and I had to look at it again. I again tried to integrate scroll-behavior but still had problems (this is probably just a documentation thing), and in the end I came up with a different (very simple) that seemed to do the job for me.
I was wondering, @taion et. al, what do you think about this approach?
It is used like this:
LDMFD commentedon Jan 21, 2016
n.b. @mmahalwy the 200ms delay hack is the actual workaround for this Issue in question
mmahalwy commentedon Jan 21, 2016
Awesome! Thanks for sharing! @cachvico
taion commentedon Jan 22, 2016
I'm probably going to rewrite this to leverage
<Router render>
when I get a chance.mmahalwy commentedon Jan 28, 2016
@taion how can i help? I dont have a ton of knowledge of how react-router works but i want to help
pc035860 commentedon Mar 18, 2016
This is actually a bug in Chromium, Opera also demonstrates the same behavior.
https://bugs.chromium.org/p/chromium/issues/detail?id=533742&q=hotlist%3Ainput-dev&sort=pri%20mstone&colspec=ID%20Pri%20Mstone%20ReleaseBlock%20OS%20Area%20Feature%20Status%20Owner%20Summary
And it's fixed in Chrome 49 released on 2 March. (commit)
http://googlechromereleases.blogspot.tw/2016/03/stable-channel-update.html
Opera also get fixed in Opera 36 two days ago
http://www.opera.com/docs/changelogs/unified/3600/
taion commentedon Apr 14, 2016
Appears to be fixed now.