Open alexandergitter opened 2 years ago
Got the same issue. This makes development on Firefox with livereload hugely annoying as you've got to scroll down manually on every change.
I've found a workaround:
Turbo.session.pageObserver.stop();
but it may break other stuff depending on whether you're using turbo drive.
Also still getting this issue on Firefox.
It'll scroll to the top every time.
Can also confirm, this happens for me in Firefox 129 on Linux, and on Firefox for Android 131
When you refresh a page relinquishControlOfScrollRestoration
restores history.scrollRestoration
back to auto
so the browser would handle scroll on full page refresh:
Then when page loads turbo assumes control over the scroll for subsequent visits:
Except in Firefox history.scrollRestoration
change doesn't seem to persist over the refresh (or probably it is set too late) and remains manual
which sets this.previousScrollRestoration
to manual as well, which means browser doesn't handle the scroll and turbo can't handle the scroll yet.
Here is a simpler way to reproduce it:
// don't forget to remove Turbo for this test
addEventListener("pagehide", function(event) {
history.scrollRestoration = "manual"
console.log("pagehide", history.scrollRestoration)
});
addEventListener("pageshow", function(event) {
console.log("pageshow", history.scrollRestoration)
});
In Chrome:
// first visit
pageshow auto
// refresh
pagehide manual
Navigated to http://0.0.0.0:3000/
pageshow manual
In Firefox:
// first visit
pageshow auto
// refresh
Navigated to http://0.0.0.0:3000/
pagehide manual
pageshow auto // ???
// refresh
Navigated to http://0.0.0.0:3000/
pagehide manual
pageshow manual
Not sure what the proper way of dealing with this would be, but here is a patch to fix it for now:
Turbo.session.history.__proto__.relinquishControlOfScrollRestoration = function() {
if (this.previousScrollRestoration) {
// history.scrollRestoration = this.previousScrollRestoration;
history.scrollRestoration = "auto";
delete this.previousScrollRestoration;
}
}
In Firefox 95 (Linux, tested on Ubuntu 20.04), Turbo causes the browser to jump back to the top of the page on a normal page refresh (F5) .
Here's some example HTML to test this. Usually it works fine for the first refresh, but on subsequent ones the page jumps back to the top.