Skip to content

debouncePause/mouseUp call preventDefault() on passive touch listeners → warning on every tap/hold #331

Description

@raiez-alshamaly

Version: 2.8.0

On touch devices, Container's debouncePause and mouseUp call e.preventDefault() unconditionally. React binds touchstart/touchend as passive listeners, so the event is non-cancelable and the browser logs on every tap/hold:

Unable to preventDefault inside passive event listener invocation.

Repro: render <Stories>, open on a touch device (or DevTools touch emulation), tap or press-and-hold — the warning fires each time.

Cause: preventDefault() is called without checking e.cancelable.

Suggested fix (src/components/Container.tsx):

 const debouncePause = (e: React.MouseEvent | React.TouchEvent) => {
-  e.preventDefault();
+  if (e.cancelable) e.preventDefault();
   mousedownId.current = setTimeout(() => {
     toggleState('pause');
   }, 200);
 };

 const mouseUp = (type: string) => (e: React.MouseEvent | React.TouchEvent) => {
-  e.preventDefault();
+  if (e.cancelable) e.preventDefault();
   mousedownId.current && clearTimeout(mousedownId.current);
   // …unchanged
 };

Functionality is unchanged (pause/nav still runs via the existing setTimeout); only the no-op call and the console warning go away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions