Skip to content

A platform for community discussion. Free, open, simple.

FIX: Upwards scrolling occasionally broken

Robin Ward8bca2647eae8
diff --git a/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6 b/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6
index faf0c660af8..b62b4400ae8 100644
--- a/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6
+++ b/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6
@@ -192,7 +192,14 @@ export default MountWidget.extend({
// Quickly going back might mean the element is destroyed
const position = $refreshedElem.position();
if (position && position.top) {
- $("html, body").scrollTop(position.top + distToElement);
+ let whereY = position.top + distToElement;
+ $("html, body").scrollTop(whereY);
+
+ // This seems weird, but somewhat infrequently a rerender
+ // will cause the browser to scroll to the top of the document
+ // in Chrome. This makes sure the scroll works correctly if that
+ // happens.
+ Ember.run.next(() => $("html, body").scrollTop(whereY));
}
});
};