Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
<header
className={`
app-header
${isSwipeMode ? 'bg-card' : 'bg-card/95 backdrop-blur-sm'}
border-b border-border
md:relative md:transform-none md:mb-0
${isSwipeMode
? 'sticky top-0 z-50 mb-[calc(-1*var(--header-height))]'
: 'fixed top-0 left-0 right-0 z-50'}
fixed top-0 left-0 right-0 z-50
${isSwipeMode ? '' : 'transition-transform duration-300 ease-out'}
${isSwipeMode ? '' : !mobileHidden ? 'translate-y-0' : '-translate-y-full'}
md:translate-y-0
Expand Down
33 changes: 33 additions & 0 deletions src/hooks/useSwipeScroll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,39 @@ describe('useSwipeScroll', () => {
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 });
Expand Down
12 changes: 12 additions & 0 deletions src/hooks/useSwipeScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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]);
Expand Down
12 changes: 12 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -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)); }
Expand Down