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.
This commit is contained in:
Jason
2026-04-20 23:46:45 +08:00
parent 29a28d2a74
commit eb1cd17ab2
+5 -2
View File
@@ -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) {