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

Remove useless return from eventProxy #2026

Merged
merged 3 commits into from
Oct 25, 2019

Conversation

jridgewell
Copy link
Contributor

I don't think there's any event handler that expects a return value, so I don't think this is needed.

@coveralls
Copy link

coveralls commented Oct 20, 2019

Coverage Status

Coverage remained the same at 99.77% when pulling c2d70ff on jridgewell:remove-useless-return into b051204 on preactjs:master.

@sventschui
Copy link
Member

Although it is bad practise (in my opinion) it is allowed to prevent default browser behaviour with a return false: https://stackoverflow.com/a/128966

For compatibility reasons I’d vote to keep the return

@cristianbote
Copy link
Member

Hey @jridgewell so with @sventschui addressing the compatibility reason, I think it's fair enough to consider this as a no-go. Compatibility is a big reason people do use preact. Our main slogan was closer to the metal since we are big on dom compatibility.

Thank you so much for looking into this! 🙇

@jridgewell
Copy link
Contributor Author

@cristianbote: Note that no browsers respect the return value.

@marvinhagemeister
Copy link
Member

Good point, I'll reopen it until we've checked/verified that against our current browser target 👍

@cristianbote
Copy link
Member

Hey @jridgewell thanks for clarifying that and also @marvinhagemeister for reopening this 😄!

So, the takeaway are these:

  • If you add an event listener as a property, dom.onclick = () => false; the default behaviour is prevented.
    Example:
<form onsubmit="return false">
  <input type="submit" value="click" />
</form>
  • If you add the event listener via addEventListener and return the value that does not prevent the default behaviour. You would either need to call the event methods or set another property on the event itself, named returnValue;
    Example:
form.addEventListener('submit', e => { e.returnValue = false; });

So the return does get respected by the browsers if you set the listener as a property.

Since we're basically never adding the events listeners as properties, I think we can remove the return statement. Thanks for pointing it out and sorry it tooks us a bit of back and forth. Really appreciate the effort! 👍

Copy link
Member

@cristianbote cristianbote left a comment

Choose a reason for hiding this comment

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

I believe that with the way we're handling event listeners makes total sense to remove the return value for the eventProxy since it's not gonna be taken into account.

Copy link
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

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

Minus bytes 🎉 great spot!

@marvinhagemeister
Copy link
Member

marvinhagemeister commented Oct 25, 2019

@cristianbote Awesome, thank you so much for getting to the bottom of this 🙌 And of course thank you so much @jridgewell for making a PR 🎉 You rock 💯

@marvinhagemeister marvinhagemeister merged commit f0fa294 into preactjs:master Oct 25, 2019
@jridgewell
Copy link
Contributor Author

Thanks for investigating @cristianbote

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.

6 participants