Skip to content

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

PERF: Set --header-offset property only when changed (#15107)

David Taylor4d3eb3f1acfc
diff --git a/app/assets/javascripts/discourse/app/components/site-header.js b/app/assets/javascripts/discourse/app/components/site-header.js
index 6be70db36f9..32045dec662 100644
--- a/app/assets/javascripts/discourse/app/components/site-header.js
+++ b/app/assets/javascripts/discourse/app/components/site-header.js
@@ -186,7 +186,13 @@ const SiteHeaderComponent = MountWidget.extend(
const headerRect = header.getBoundingClientRect(),
headerOffset = headerRect.top + headerRect.height,
doc = document.documentElement;
- doc.style.setProperty("--header-offset", `${headerOffset}px`);
+
+ const newValue = `${headerOffset}px`;
+ if (newValue !== this.currentHeaderOffsetValue) {
+ this.currentHeaderOffsetValue = newValue;
+ doc.style.setProperty("--header-offset", newValue);
+ }
+
if (offset >= this.docAt) {
if (!this.dockedHeader) {
document.body.classList.add("docked");