-
-
Notifications
You must be signed in to change notification settings - Fork 260
Open
Description
Bug Description
Radio button and checkbox click events do not trigger React onChange handlers in happy-dom v20.0.0, despite being fixed in earlier versions. This is a regression from v9.10.3 and v14.10.2.
Versions
- happy-dom: 20.0.0
- Affected: Radio buttons and checkboxes with React Hook Form
- Environment: vitest v2.1.9, React 18, @testing-library/user-event
Previous Fixes
- ✅ v9.10.3: Fixed radio/checkbox onChange issue (onChange events do not work on checkbox and radio button elements #880, PR #880@patch: Fixes issue where react "onChange" listener never got tri… #884)
- ✅ v14.10.2: Fixed regression from v13.7.0 (Regression from 13.6.2 to 13.7.0: clicking a checkbox no longer fires a
changeevent #1397) - ❌ v20.0.0: Issue has regressed again
Reproduction
Test Code
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
it('radio button onChange should trigger', async () => {
const handleChange = vi.fn();
const user = userEvent.setup();
render(
<div>
<label>
<input type="radio" name="test" value="option1" onChange={handleChange} />
Option 1
</label>
<label>
<input type="radio" name="test" value="option2" onChange={handleChange} />
Option 2
</label>
</div>
);
const radio2 = screen.getByRole('radio', { name: /Option 2/i });
await user.click(radio2);
// ❌ FAILS: onChange is not triggered
await waitFor(() => {
expect(handleChange).toHaveBeenCalled();
});
});
vitest.config.ts
export default defineConfig({
test: {
environment: 'happy-dom',
environmentOptions: {
happyDOM: {
settings: {
disableJavaScriptEvaluation: false, // Tried this, doesn't help
},
},
},
},
});Expected Behavior
Clicking a radio button or checkbox should:
- Update the
checkedproperty - Trigger the
changeevent - Call React's
onChangehandler
This worked correctly in v9.10.3 - v19.x.
Actual Behavior
- ❌
checkedproperty does not update - ❌
changeevent is not fired - ❌ React
onChangehandler is not called
Attempted Workarounds (all failed)
- Setting
disableJavaScriptEvaluation: falsein vitest config - Using
fireEvent.click()instead ofuser.click() - Clicking the label element instead of the input
- Manually dispatching change events
- Using
act()wrapper
Environment
- Node.js: v20.x
- OS: Linux
- Testing Framework: Vitest 2.1.9
- React: 18.x
- React Testing Library: 16.x
- React Hook Form: 7.x
Additional Context
We cannot downgrade to v19 or earlier due to CVE-2025-61927 (CVSS 9.4 - Critical), which requires v20.0.0+.
Related Issues
- onChange events do not work on checkbox and radio button elements #880 - Original fix in v9.10.3
- Regression from 13.6.2 to 13.7.0: clicking a checkbox no longer fires a
changeevent #1397 - Regression in v13.7.0, fixed in v14.10.2
Would appreciate any guidance on this regression. Thank you!
Metadata
Metadata
Assignees
Labels
No labels