Skip to content

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

Description

@rj-luo

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

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.`)
    }
  }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions