FIX: Prevent content layout shift on mobile (#26238)

This commit is contained in:
Natalie Tay 2024-03-19 16:56:32 +08:00 committed by GitHub
parent 4f24e3b3b2
commit 0bf87c5ed8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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(),
});
});
});
};