mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-05-24 23:10:39 +08:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user