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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions