Skip to content
Source
Sign inSign up
TanStack/redact

Dispatched mouse events call onClick/onMouseDown on disabled buttons (React skips them) #139

Openwiesson(GitHub profile, opens in a new tab) opened this issue 1 comment

Version: @tanstack/redact 0.2.5

A dispatched click on a disabled <button> calls its onClick under Redact. React doesn't: its event system skips mouse events (onClick, onMouseDown, onMouseUp, onDoubleClick, …) on disabled button, input, select and textarea elements (shouldPreventMouseEvent in React DOM).

Real user clicks are unaffected, because browsers don't deliver them to disabled form controls. But element.dispatchEvent(new MouseEvent("click")) and Testing Library's fireEvent.click do reach the element, so tests asserting that a disabled button does nothing fail under Redact.

Repro (Vitest + jsdom + Testing Library)

// @vitest-environment jsdom
import { render, fireEvent } from "@testing-library/react";
import { expect, it, vi } from "vitest";

it("does not call onClick on a disabled button", () => {
  const onClick = vi.fn();
  const onMouseDown = vi.fn();
  const { getByRole } = render(
    <button disabled onClick={onClick} onMouseDown={onMouseDown}>Send</button>
  );
  const button = getByRole("button");
  fireEvent.click(button);
  fireEvent.mouseDown(button);
  button.dispatchEvent(new MouseEvent("click", { bubbles: true }));
  expect(onClick).not.toHaveBeenCalled();
  expect(onMouseDown).not.toHaveBeenCalled();
});
onClick callsonMouseDown calls
React 190 ✅0 ✅
Redact 0.2.52 ❌1 ❌

Expected

Like React: don't dispatch mouse event handlers to a disabled button/input/select/textarea (or to handlers on the disabled element when the event targets it).

Found in a TanStack Start app: a test checks that a "send" button stays inert while an earlier send is still unclear (disabled set, then fireEvent.click). It passes under React and fails under Redact.

  1. Thanks for the clear reproduction. This is confirmed, and a candidate fix now matches React in the browser checks.

    AI review notes: All 2,072 tests, types, build and build verification pass. Nine browser records compare native React, unchanged main and the candidate in Chromium, Firefox and WebKit. They cover disabled and enabled form controls in both mouse phases, ancestor handlers, unrelated events and external changes to native disabled properties. The fix tracks the rendered disabled prop, as React does. The unchanged runtime still calls the disabled handlers in those controls. Size checks still reject the candidate, at most 101 bytes gzip or 158 bytes Brotli, with eight fixed limits needing 42 to 93 more gzip bytes. The exact decision has been requested, this has not been pushed, merged or released yet.

Sign in to join this conversation.