A platform for community discussion. Free, open, simple.
DEV: Cleanup `body.scrollTop` usage (#16445)
Penar Musaraj0bef5af582d1
diff --git a/app/assets/javascripts/discourse/app/components/scrolling-post-stream.js b/app/assets/javascripts/discourse/app/components/scrolling-post-stream.jsindex a871521bcd0..c6c088decbc 100644--- a/app/assets/javascripts/discourse/app/components/scrolling-post-stream.js+++ b/app/assets/javascripts/discourse/app/components/scrolling-post-stream.js@@ -58,24 +58,6 @@ export default MountWidget.extend({);},- beforePatch() {- this.prevHeight = document.body.clientHeight;- this.prevScrollTop = document.body.scrollTop;- },-- afterPatch() {- const height = document.body.clientHeight;-- // This hack is for when swapping out many cloaked views at once- // when using keyboard navigation. It could suddenly move the scroll- if (- this.prevHeight === height &&- document.body.scrollTop !== this.prevScrollTop- ) {- document.body.scroll({ left: 0, top: this.prevScrollTop });- }- },-scrolled() {if (this.isDestroyed || this.isDestroying) {return;@@ -103,8 +85,7 @@ export default MountWidget.extend({const slack = Math.round(windowHeight * 5);const onscreen = [];const nearby = [];- const windowTop =- document.documentElement.scrollTop || document.body.scrollTop;+ const windowTop = document.scrollingElement.scrollTop;const postsWrapperTop = domUtils.offset(document.querySelector(".posts-wrapper")).top;@@ -203,9 +184,7 @@ export default MountWidget.extend({const elem = postsNodes.item(onscreen[0]);const elemId = elem.id;const elemPos = domUtils.position(elem);- const distToElement = elemPos- ? document.body.scrollTop - elemPos.top- : 0;+ const distToElement = elemPos?.top || 0;const topRefresh = () => {refresh(() => {@@ -214,7 +193,7 @@ export default MountWidget.extend({// Quickly going back might mean the element is destroyedconst position = domUtils.position(refreshedElem);if (position && position.top) {- let whereY = position.top + distToElement;+ let whereY = position.top - distToElement;document.documentElement.scroll({ top: whereY, left: 0 });// This seems weird, but somewhat infrequently a rerenderdiff --git a/app/assets/javascripts/discourse/app/components/site-header.js b/app/assets/javascripts/discourse/app/components/site-header.jsindex d541ad74da9..82a4d9f843a 100644--- a/app/assets/javascripts/discourse/app/components/site-header.js+++ b/app/assets/javascripts/discourse/app/components/site-header.js@@ -444,6 +444,5 @@ export default SiteHeaderComponent.extend({export function headerTop() {const header = document.querySelector("header.d-header");- const headerOffsetTop = header.offsetTop ? header.offsetTop : 0;- return headerOffsetTop - document.body.scrollTop;+ return header.offsetTop ? header.offsetTop : 0;}