Passive Event Listeners and Compositor Scrolling vs Pointer Events, touch-action, and Pointer Capture
Passive listeners promise no preventDefault() in JS, whereas CSS touch-action declares scroll constraints to the compositor.
Structured Comparison Matrix
| Dimension | Passive Event Listeners and Compositor Scrolling | Pointer Events, touch-action, and Pointer Capture |
|---|---|---|
| Mental Model | Eliminate 100ms+ mobile scroll-start jank—{ passive: true } promises the GPU compositor thread that wheel/touch listeners will never call preventDefault(). | Stop mobile browser scroll from hijacking custom drags and sliders—CSS touch-action negotiates gesture ownership on the compositor while setPointerCapture() locks fast pointer streams. |
| Maturity & Domain | Baseline · Widely · DOM & Events Chrome 51+ · Firefox 49+ · Safari 10+ | Baseline · Widely · DOM & Events Chrome 55+ · Firefox 59+ · Safari 13+ |
| Prerequisites | ||
| When Not to Use | When not to use { passive: false }: Avoid { passive: false } on general page wrappers just to suppress scroll conditionally; use CSS touch-action via Pointer Events & touch-action instead. | When not to use touch-action: none: Never apply touch-action: none to large scrollable sections, it traps mobile users who try to scroll past the widget. |
Engine Mechanics & Trade-Offs
Non-passive wheel/touch listeners force the compositor thread to wait for main-thread JS to check preventDefault(); { passive: true } unlocks immediate compositor scrolling.
Key Pitfalls: Ignored preventDefault() on document: Calling e.preventDefault() inside a document-level wheel listener logs a warning and fails to stop scrolling unless { passive: false } is set. Third-Party Tracking Scripts: Non-passive touchstart listeners attached to inner containers silently re-introduce scroll jank.
CSS touch-action instructs the compositor up front which gestures belong to the browser vs JS, preventing pointercancel during custom drags.
Key Pitfalls: Missing touch-action on Sliders: Forgetting touch-action: pan-y on a horizontal carousel causes mobile browsers to abort drags with pointercancel. Orphaned Drag State: Relying on pointerup on the knob without setPointerCapture() drops the release event when the cursor leaves the element.