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

Warn early if event listener is not a function #10407

Closed
gaearon opened this issue Aug 8, 2017 · 9 comments
Closed

Warn early if event listener is not a function #10407

gaearon opened this issue Aug 8, 2017 · 9 comments
Assignees

Comments

@gaearon
Copy link
Collaborator

gaearon commented Aug 8, 2017

We used to throw if event listener is not a function in Stack:

ReactDOM.render(
  <h1 onClick={{}}>Hello World!</h1>,
  document.getElementById('container')
);

screen shot 2017-08-08 at 3 41 08 pm

Fiber silently ignores this.

I think we should throw. This would let us add support for objects (e.g. for passive listener configuration) if we want to in a minor rather than a major.

@aweary
Copy link
Contributor

aweary commented Aug 8, 2017

I'll take this one 😀

@gaearon
Copy link
Collaborator Author

gaearon commented Aug 8, 2017

You got it!

@aweary
Copy link
Contributor

aweary commented Aug 8, 2017

@gaearon so it looks like Fiber will throw the same error, but it does so lazily. Once you try to click the element it will trigger that invariant. The invariant currently lives in EventPluginHub.getListener, so we could just move it somewhere else like ReactDOMFiberComponent so we throw early?

@gaearon
Copy link
Collaborator Author

gaearon commented Aug 8, 2017

I would prefer that.

@gaearon
Copy link
Collaborator Author

gaearon commented Aug 8, 2017

It's worth double checking with @sebmarkbage if this was intentional.

@sebmarkbage
Copy link
Collaborator

This was indeed intentional. We could warn early, but not throw. Because we should be able to lazily deal with event listeners by only looking at the properties when an event is triggered. Currently we loop over them all but this is an optimizable path.

@gaearon
Copy link
Collaborator Author

gaearon commented Aug 8, 2017

Warning early sounds sensible then.

@aweary aweary changed the title Throw if event listener is not a function Warn early if event listener is not a function Aug 11, 2017
@flarnie
Copy link
Contributor

flarnie commented Aug 13, 2017

Hi - just wondering what the status is on this.

@aweary
Copy link
Contributor

aweary commented Aug 13, 2017

@flarnie great timing, I just opened #10453 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants