From ce27dbd5606dac7dbb969a081be957d8a2f981d8 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Mon, 19 Sep 2022 18:26:34 +0530 Subject: [PATCH] FIX: header offset position was not correct in some cases (#18155) When a topic is opened in a new tab and is fully loaded the scroll position is a bit off. This commit partially reverts 9a55c9c4339214ea18a73e71ab2506e4ad2967aa. --- .../discourse/app/components/site-header.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/assets/javascripts/discourse/app/components/site-header.js b/app/assets/javascripts/discourse/app/components/site-header.js index 2331149c995..e44bb9643db 100644 --- a/app/assets/javascripts/discourse/app/components/site-header.js +++ b/app/assets/javascripts/discourse/app/components/site-header.js @@ -177,6 +177,19 @@ const SiteHeaderComponent = MountWidget.extend( this.docAt = header.offsetTop; } + const headerRect = header.getBoundingClientRect(); + let headerOffsetCalc = headerRect.top + headerRect.height; + + if (window.scrollY < 0) { + headerOffsetCalc += window.scrollY; + } + + const newValue = `${headerOffsetCalc}px`; + if (newValue !== this.currentHeaderOffsetValue) { + this.currentHeaderOffsetValue = newValue; + document.documentElement.style.setProperty("--header-offset", newValue); + } + const main = document.querySelector(".ember-application"); const offsetTop = main ? main.offsetTop : 0; const offset = window.pageYOffset - offsetTop;