[Bug] `setPointerCapture` in `pointerDown` should be wrapped in try-catch

Author: rj-luoCreated Mar 6, 2026Updated Mar 6, 2026

Bug Description

When using useDrag with pointer.capture: true (default), setPointerCapture in pointerDown() throws DOMException: InvalidPointerId when pointer is cancelled before capture is established (e.g., rapid tapping on mobile).

Error

DOMException: Failed to execute 'setPointerCapture' on 'Element': InvalidPointerId.
    at pointerDown (DragEngine.ts:93)

Issue

releasePointerCapture in pointerUp() has try-catch protection, but setPointerCapture in pointerDown() does not.

Proposed Fix

typescript
if (config.pointerCapture) {
  try {
    ;(event.target as HTMLElement).setPointerCapture(event.pointerId)
  } catch {
    if (process.env.NODE_ENV === 'development') {
      console.warn(`[@use-gesture]: Failed to capture pointer.`)
    }
  }
}