Skip to content

Commit a4074e5

Browse files
committed
fix(settings): prevents header oscillation during smooth scroll
The scroll listener that shrinks/expands the header was firing during programmatic TOC scrolling, causing a feedback loop: scroll crosses 50px threshold → header resizes → content shifts → scroll position changes → header resizes again. Uses a data-scrollLock attribute to suppress header state updates during TOC-driven scroll animations. Dispatches a synthetic scroll event on completion to sync final state.
1 parent 66ffaba commit a4074e5

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/app/components/settings/SettingsPage.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ export default function SettingsPage() {
8282

8383
const [scrolled, setScrolled] = createSignal(false);
8484
onMount(() => {
85-
const onScroll = () => setScrolled(window.scrollY > 50);
85+
const onScroll = () => {
86+
if (document.documentElement.dataset.scrollLock) return;
87+
setScrolled(window.scrollY > 50);
88+
};
8689
window.addEventListener("scroll", onScroll, { passive: true });
8790
onCleanup(() => window.removeEventListener("scroll", onScroll));
8891
});

src/app/components/settings/SettingsTOC.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,14 @@ export default function SettingsTOC() {
109109
function scrollToSection(id: string) {
110110
scrollEndCleanup?.();
111111
setScrollingTo(id);
112+
document.documentElement.dataset.scrollLock = "1";
112113
const el = document.getElementById(id);
113-
if (!el) { setScrollingTo(null); return; }
114+
if (!el) { setScrollingTo(null); delete document.documentElement.dataset.scrollLock; return; }
114115
const prefersReduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
115116
const clear = () => {
116117
setScrollingTo(null);
118+
delete document.documentElement.dataset.scrollLock;
119+
window.dispatchEvent(new Event("scroll"));
117120
scrollEndCleanup = undefined;
118121
};
119122
if (prefersReduced) {

0 commit comments

Comments
 (0)