From 0bf87c5ed894292f2962984c472ae99a06154208 Mon Sep 17 00:00:00 2001 From: Natalie Tay Date: Tue, 19 Mar 2024 16:56:32 +0800 Subject: [PATCH] FIX: Prevent content layout shift on mobile (#26238) --- .../discourse/app/components/scrolling-post-stream.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/scrolling-post-stream.js b/app/assets/javascripts/discourse/app/components/scrolling-post-stream.js index b56a3124677..ad8f629179f 100644 --- a/app/assets/javascripts/discourse/app/components/scrolling-post-stream.js +++ b/app/assets/javascripts/discourse/app/components/scrolling-post-stream.js @@ -206,15 +206,18 @@ export default MountWidget.extend({ return element.offsetTop + getOffsetTop(element.offsetParent); }; - const top = getOffsetTop(refreshedElem) - offsetCalculator(); - window.scrollTo({ top }); + window.scrollTo({ + top: getOffsetTop(refreshedElem) - offsetCalculator(), + }); // 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. schedule("afterRender", () => { - window.scrollTo({ top }); + window.scrollTo({ + top: getOffsetTop(refreshedElem) - offsetCalculator(), + }); }); }); };