Skip to content

Fix double-firing submit events - #12877

Merged
sophiebits merged 1 commit into
react:masterfrom
sophiebits:sr
May 22, 2018
Merged

sophiebits merged 1 commit into
react:masterfrom
sophiebits:sr

Conversation

@sophiebits

Copy link
Copy Markdown
Collaborator

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>
    );
  }
};

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>
    );
  }
};
```
@sophiebits

sophiebits commented May 22, 2018 •

Copy link
Copy Markdown
Collaborator Author

@philipp-spiess Looks like your refactor introduced this. Previously we added this listener only if it's present in topLevelTypes, which topSubmit and topReset weren't.

Neither were any of the media events – to my eyes the ones we shouldn't add top-level listeners for are:

pause play rateChange reset seeked submit volumeChange
abort canPlay canPlayThrough durationChange emptied encrypted ended error loadedData loadedMetadata playing progress seeking stalled suspend timeUpdate waiting

These are the ones that are in the interactive + noninteractive arrays in SimpleEventPlugin that were not in the old topLevelTypes. I am only adding submit and reset here because I believe they are the only ones that can ever bubble natively to the root.

Going to merge this now as an urgent fix, but would you be able to submit a less hacky fix for this and tests to make sure we don't regress? Should be doable with native event dispatching. Maybe we can add a fixture that tests this too.

@sophiebits
sophiebits merged commit ad27845 into react:master May 22, 2018
@gaearon

gaearon commented May 22, 2018

Copy link
Copy Markdown
Collaborator

I misunderstood this line, sorry.

#12629 (comment)

I thought it meant “all valid top-level type constants” and forgot topLevelTypes was something else.

@gaearon

gaearon commented May 22, 2018

Copy link
Copy Markdown
Collaborator

#12878

@philipp-spiess

Copy link
Copy Markdown
Contributor

What a silly mistake - sorry for the troubles 🤦‍♀️ Thank you @sophiebits for pining me on this so I can follow along - I really appreciate that! And great work @gaearon on fixing this up so quickly and writing high quality tests.

mrizwanashiq pushed a commit to mrizwanashiq/react that referenced this pull request Jun 25, 2026
We were adding a listener at the root when we weren't meant to. Blames to 17b9c8b.

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>
    );
  }
};
```
hanzo-dev pushed a commit to hanzoai/react that referenced this pull request Sep 9, 2026
We were adding a listener at the root when we weren't meant to. Blames to 02ffc11.

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>
    );
  }
};
```
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.

4 participants