Skip to content

Commit ad27845

Browse files
authored
Fix double-firing submit events (#12877)
We were adding a listener at the root when we weren't meant to. Blames to e96dc14. This now alerts once (at FORM) instead of twice (at FORM, #document): ``` var Hello = class extends React.Component { render() { return ( <form onSubmit={(e) => {e.preventDefault(); alert('hi ' + e.nativeEvent.currentTarget.nodeName);}}> <button>hi</button> </form> ); } }; ```
1 parent 60853f0 commit ad27845

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

packages/react-dom/src/events/ReactBrowserEventEmitter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import {
1313
TOP_CANCEL,
1414
TOP_CLOSE,
1515
TOP_FOCUS,
16+
TOP_RESET,
1617
TOP_SCROLL,
18+
TOP_SUBMIT,
1719
} from './DOMTopLevelEventTypes';
1820
import {
1921
setEnabled,
@@ -147,7 +149,7 @@ export function listenTo(
147149
trapCapturedEvent(TOP_CLOSE, mountAt);
148150
}
149151
isListening[TOP_CLOSE] = true;
150-
} else {
152+
} else if (dependency !== TOP_SUBMIT && dependency !== TOP_RESET) {
151153
trapBubbledEvent(dependency, mountAt);
152154
}
153155

0 commit comments

Comments
 (0)