From eb1cd17ab29629b2ef6fdf7b38882d57f1743f30 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 20 Apr 2026 23:46:45 +0800 Subject: [PATCH] fix(header): stop auto-compact from latching after maximize useAutoCompact cached normalWidthRef = el.scrollWidth on every non-compact resize, but per DOM spec scrollWidth === clientWidth when content fits. Maximizing the window (content no longer overflows) therefore wrote the container width into normalWidthRef, making it impossible to re-enter compact when the window was restored to its original size. Move the assignment inside the overflow branch so the cache is only written at the actual compact threshold, where scrollWidth reflects the real content width. --- src/hooks/useAutoCompact.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hooks/useAutoCompact.ts b/src/hooks/useAutoCompact.ts index 3ba8abe5f..b5b7bca39 100644 --- a/src/hooks/useAutoCompact.ts +++ b/src/hooks/useAutoCompact.ts @@ -25,10 +25,13 @@ export function useAutoCompact( if (Date.now() < lockUntilRef.current) return; if (!compact) { - // Cache the total content width in normal mode - normalWidthRef.current = el.scrollWidth; // Overflow detected → switch to compact if (el.scrollWidth > el.clientWidth + 1) { + // Cache only at the overflow edge: when content fits, + // scrollWidth === clientWidth (DOM spec), so caching unconditionally + // would pollute normalWidthRef with the container width (e.g. after + // maximizing), making the expand threshold unreachable. + normalWidthRef.current = el.scrollWidth; setCompact(true); } } else if (normalWidthRef.current > 0) {