diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 1fe0ced..37e08a4 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -227,18 +227,16 @@ export function Header() { }; return ( - // Swipe mode pins the header with `sticky` (not `fixed`) so Firefox Android's - // URL bar can't re-anchor it mid-swipe (the blink fix). The negative margin - // cancels the flow height `sticky` adds, which would otherwise double up with - // the panel's `padding-top: var(--header-height)`. + // Swipe-mode header is `position: fixed` to dodge Gecko's sticky scroll-up + // flicker (see index.css). useSwipeScroll adds `is-swiping` during the panel + // swap to flip it back to `sticky`; `app-header` is the hook the override targets.
{ await act(async () => { /* flush */ }); }); + it('flags is-swiping for a horizontal swipe but not a vertical gesture', () => { + // Guards the flicker fix: `is-swiping` (→ sticky) is set ONLY for a horizontal + // swipe, never a vertical scroll, which must stay `fixed`. + render(createElement(TestHarness), { wrapper: Wrapper }); + const container = getContainer(); + + swipeGesture(container, 'left', 150); + expect(document.body.classList.contains('is-swiping')).toBe(true); + + dispatchTouch(container, 'touchstart', CENTER_X, CENTER_Y); + expect(document.body.classList.contains('is-swiping')).toBe(false); + dispatchTouch(container, 'touchmove', CENTER_X, CENTER_Y - 120); + dispatchTouch(container, 'touchend', CENTER_X, CENTER_Y - 120); + expect(document.body.classList.contains('is-swiping')).toBe(false); + + act(() => { vi.runAllTimers(); }); + }); + + it('keeps is-swiping set through the commit swap (blink guard)', () => { + // commitPanelSwap runs after touchend, so `is-swiping` must survive it (clearing + // at touchend repaints the swap `fixed` → blink, 86e7f98) and only clear on the + // next touchstart. + reducedMotionValue = true; // synchronous commit, so the swap definitely runs + render(createElement(TestHarness), { wrapper: Wrapper }); + + swipeGesture(getContainer(), 'left', 150); + act(() => { vi.runAllTimers(); }); + expect(document.body.classList.contains('is-swiping')).toBe(true); + + dispatchTouch(getContainer(), 'touchstart', CENTER_X, CENTER_Y); + expect(document.body.classList.contains('is-swiping')).toBe(false); + }); + it('keeps outgoing panel in flow for non-zero scroll restores', async () => { reducedMotionValue = true; render(createElement(TestHarness), { wrapper: Wrapper }); diff --git a/src/hooks/useSwipeScroll.ts b/src/hooks/useSwipeScroll.ts index 5a6effb..9d6a49e 100644 --- a/src/hooks/useSwipeScroll.ts +++ b/src/hooks/useSwipeScroll.ts @@ -422,6 +422,10 @@ export function useSwipeScroll({ return; } + // Header is `fixed` by default (flicker-free vertical scroll); clear any + // lingering `is-swiping` so a prior swipe can't keep it sticky into this scroll. + document.body.classList.remove('is-swiping'); + // Clean slate: cancel stale animations and residual classes const hadActiveAnimations = runningAnimations.length > 0; cleanSlate(); @@ -483,6 +487,9 @@ export function useSwipeScroll({ isSwiping = true; // Hide scroll indicator immediately to prevent visible jump during swipe document.body.classList.remove('is-scrolling'); + // Re-sticky the header for the swap: `fixed` blinks during the panel + // swap on Firefox Android, `sticky` doesn't (index.css `.is-swiping`). + document.body.classList.add('is-swiping'); // Cache panel width at lock time to avoid layout reads during drag cachedPanelWidth = container.clientWidth || window.innerWidth; // Lock direction and determine target @@ -522,6 +529,10 @@ export function useSwipeScroll({ return; } + // Do NOT clear `is-swiping` here: commitPanelSwap runs after touchend (rAF/ + // onfinish, or sync for reduced motion); the header must stay sticky through + // the swap or the blink returns (86e7f98). Next touchstart resets it to `fixed`. + // Read live (not cached at effect setup) so a mid-session OS toggle is // honored on the very next gesture, matching the CSS media query. const reducedMotion = prefersReducedMotion(); @@ -763,6 +774,7 @@ export function useSwipeScroll({ pendingTimeouts.forEach(id => clearTimeout(id)); isSuppressingScrollIndicatorRef.current = false; gestureId++; + document.body.classList.remove('is-swiping'); delete container.dataset.swipeEnabled; }; }, [enabled, activatePanel, activatePanelAndRestoreScroll]); diff --git a/src/index.css b/src/index.css index b4909ff..0053314 100644 --- a/src/index.css +++ b/src/index.css @@ -480,6 +480,18 @@ body.swipe-mode.is-scrolling::after { opacity: 1; } +/* Header is `position: fixed` by default (see Header.tsx): Gecko's APZ flickers a + sticky header during fast scroll-up (bug 1585378). `fixed` only blinks during the + panel swap, so useSwipeScroll adds `is-swiping` (lock → commit) to flip it back to + sticky there. Negative margin + `left/right: auto` keep it flow-neutral, matching + the proven blink-fix sticky. `.app-header` avoids UserProfile's headers. */ +body.swipe-mode.is-swiping .app-header { + position: sticky; + left: auto; + right: auto; + margin-bottom: calc(-1 * var(--header-height)); +} + @keyframes scroll-thumb { from { transform: translateY(0); } to { transform: translateY(calc((var(--swipe-viewport-height, 100vh) - var(--header-height) - var(--network-bar-height)) * 0.8)); }