Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert #1536" #3246

Merged
merged 2 commits into from
Mar 10, 2015
Merged

Revert "Revert #1536" #3246

merged 2 commits into from
Mar 10, 2015

Conversation

sophiebits
Copy link
Collaborator

Formerly "Attach empty onclick listener to each node" (#1536). This reverts commit 431155d and adds a fix on top for the bug I had.

Fixes #1169.

Formerly "Attach empty onclick listener to each node". This reverts commit 431155d.
Without this, transitioning from `<div onClick={null} />` to `<div />` triggered `willDeleteListener` to delete the `click` handler which caused problems; now, we only call `putListener` and `deleteListener` when we have an actual listener.

I now also clean up the `onClickListeners` map upon deletion and don't double-listen when updating the event listener.
@sophiebits
Copy link
Collaborator Author

@yungsters Mind reviewing? You originally reviewed #1536 – this reverts your revert of that and adds a second commit on top to fix the issue it had, which was that when transitioning from <div onClick={null} /> to <div />, we'd try to delete the empty onclick listener from the DOM, but it wasn't present. Now we don't try to call didPutListener and willPutListener with falsy listeners at all.

I tested the original case that reproed the bug (t4444220) and it works correctly after this second commit.

var bankForRegistrationName = listenerBank[registrationName];
// TODO: This should never be null -- when is it?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should never be null -- when is it?

Hmm... when onClick={null} like you're trying to guard against in ReactDOMComponent.js?

What if instead of checking lastProps[propKey] in ReactDOMComponent.js, you only invoked PluginModule.willDeleteListener if !!bankForRegistrationName?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean, if bankForRegistrationName[id]? I had that originally but it seemed like willDeleteListener should also be called if you switch from a function to null, which means that EventPluginHub.putListener probably needs to delegate to EventPluginHub.deleteListener if the listener is null… but the putListener function in ReactDOMComponent also does some enqueueing so now we're having listener deletion happen at a different time depending on whether it's gone completely from props or if it's just falsy…

It seemed easier to make ReactDOMComponent call putListener/deleteListener only when an actual listener is present and have EventPluginHub not worry about falsy values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I see. Agreed. Do you think we should add a warning to deleteListener, then?

Either way, this looks good to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. I didn't really change this though, just added the TODO. Will probably merge as-is and then maybe add the warning later.

sophiebits added a commit that referenced this pull request Mar 10, 2015
@sophiebits sophiebits merged commit e8af59c into facebook:master Mar 10, 2015
sophiebits added a commit to sophiebits/react that referenced this pull request Sep 30, 2015
I accidentally regressed this in facebook#3246. Now this matches what we already checked for updates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MobileSafariClickEventPlugin requires touch events to be initialized
2 participants