FIX: Restore stream position in safari (#9993)

Safari uses an aggressive back/forward cache, which means the app loads
very quickly when hitting Back. But, in topics with > 30 posts, hitting
Back runs post stream calculations too early, which means that users
get taken back to an earlier point in the stream, consistently.

Using `onpageshow`, we can restore the correct location before the post
stream calculations take place.
This commit is contained in:
Penar Musaraj 2020-06-08 10:13:46 -04:00 committed by GitHub
parent 052c91770f
commit bdba17cdf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -333,6 +333,13 @@ export default MountWidget.extend({
});
this.appEvents.on("post-stream:refresh", this, "_refresh");
// restore scroll position on browsers with aggressive BFCaches (like Safari)
window.onpageshow = function(event) {
if (event.persisted) {
DiscourseURL.routeTo(this.location.pathname);
}
};
},
willDestroyElement() {