Skip to content

fix: Restore beforeInput event in React textareas on Firefox (#24358)#36711

Open
adambaialiev wants to merge 1 commit into
facebook:mainfrom
adambaialiev:feat/beforeinput-firefox
Open

fix: Restore beforeInput event in React textareas on Firefox (#24358)#36711
adambaialiev wants to merge 1 commit into
facebook:mainfrom
adambaialiev:feat/beforeinput-firefox

Conversation

@adambaialiev
Copy link
Copy Markdown

Summary

Fix for issue #24358: the beforeInput event does not fire from React-rendered textareas on Firefox during text replacement scenarios (macOS accent popup replacement, spellcheck correction).

Root Cause

The onBeforeInput event plugin only registered against textInput native events, which Firefox does not dispatch. Firefox uses the standard beforeinput event instead. Since React never attached a delegated native listener for beforeinput, the event was silently dropped for textarea elements on Firefox.

Fix

  1. BeforeInputEventPlugin.js: Added beforeinput to the dependency list in registerTwoPhaseEvent so React attaches a native listener for it. In the extraction logic, when the native event is beforeinput and TextEvent support is not available (i.e., Firefox), the event data is extracted from the native beforeinput event. When TextEvent is available (WebKit), beforeinput is ignored to avoid double-firing.

  2. BeforeInputEventPlugin-test.js: Added a dedicated regression test "should extract onBeforeInput from native beforeinput on textarea" that simulates a Firefox-like environment and verifies the event fires correctly.

Changed Files

  • packages/react-dom-bindings/src/events/plugins/BeforeInputEventPlugin.js (+7/-1)
  • packages/react-dom/src/events/plugins/__tests__/BeforeInputEventPlugin-test.js (+26/-0)

Test Results

  • BeforeInputEventPlugin tests: 8 passed (including new test)
  • ReactDOMTextarea tests: 53 passed, 0 failed

Reference

Prior PR #31970 provided a similar approach but was closed without review.

@meta-cla meta-cla Bot added the CLA Signed label Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant