Skip to content

feat(core): detect middle-click autoscroll and yield wheel events (#528) - #536

Open
clementroche wants to merge 3 commits into
mainfrom
feat/auto-scroll-detection
Open

feat(core): detect middle-click autoscroll and yield wheel events (#528)#536
clementroche wants to merge 3 commits into
mainfrom
feat/auto-scroll-detection

Conversation

@clementroche

@clementroche clementroche commented Aug 3, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #528 (wheel vs middle-click autoscroll jitter). Replaces the bare reset-on-middle-click with an AutoScrollDetection class that tracks the browser's native autoscroll lifecycle, so lenis can stop smoothing wheel events while native autoscroll is driving the scroll.

  • Phase state machine: middle pointerdown starts autoscroll (phase 1), its pointerup latches sticky mode (phase 2), and the next click's pointerup — any button — exits (phase 3). While phases 1–2 are active, onVirtualScroll ignores wheel events and lets the browser handle them.
  • toggle event fires on enter/exit and resets lenis's animated scroll state, replacing the previous unconditional reset on middle pointerdown.
  • Keydown/blur escape hatches: any keydown resets detection to idle — keyboard input exits native autoscroll in Chromium — and so does window blur, since after a focus loss the state can't be trusted. Both keep the flag from going stale and silently disabling wheel smoothing.
  • Chromium-on-Windows only: native middle-click autoscroll only ships enabled in Blink on Windows, so detection doesn't attach anywhere else (Windows + Chrome UA check — Edge/Brave/Opera keep the Chrome token; Firefox/Safari don't match). Prevents the flag from going stale on platforms where the pointer events fire but no autoscroll follows.
  • Link guard: middle-click on an <a> opens a tab instead of autoscrolling, so it doesn't arm the flag.

Test plan

  • Real middle-click on Windows Chrome: sticky autoscroll, then wheel — no fighting/jitter, exit click restores smoothing
  • Drag-mode autoscroll (hold middle + drag), release, then wheel
  • Press a key during sticky autoscroll — autoscroll exits and wheel smoothing is restored
  • Middle-click on a link: new tab opens, wheel smoothing unaffected
  • Alt-tab away during sticky autoscroll, come back, wheel smoothing restored
  • macOS/Firefox: middle-click leaves wheel smoothing untouched

Native autoscroll can't be triggered synthetically (CDP/dispatched events), so this needs real hardware verification on Windows.

🤖 Generated with Claude Code

@clementroche
clementroche requested a review from a team as a code owner August 3, 2026 16:51
@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lenis-playground Ready Ready Preview Aug 11, 2026 1:09pm

clementroche and others added 3 commits August 11, 2026 09:34
Track the browser's native middle-click autoscroll with a small phase
state machine (middle pointerdown starts it, pointerup latches sticky
mode, the next click's pointerup exits) and ignore wheel events while it
is active so lenis doesn't fight the native scrolling.

Detection only attaches on Chromium on Windows — the only place native
autoscroll ships enabled — and skips middle-clicks on links, which open
a tab instead of autoscrolling.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant