-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix deprecated event.returnValue in Chrome #1429
Conversation
You don't need to check if And from the API Docs:
So maybe we need to avoid |
e.preventDefault(); | ||
e.returnValue = returnValue || false; | ||
if (e.preventDefault) { | ||
e.preventDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic here seems a bit flawed. Prior to your change, e.preventDefault
was invoked without checking if said method actually existed. Therefore, your additional if
statement will always evaluate to true
.
preventDefault
is manually attached to the Event
object somewhere along the line...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right.
Sorry, I misunderstanded the code here, I have doubted why we have returnValue
and preventDefault
at the same time. Seems we set returnValue
property here for other use which I am not familiar, and the preventDefault
is always exist.
I will reread relative code,thanks for explaning.
@juandopazo I noticed the Thanks for explaning. I also think avoid |
hi @juandopazo, I have made a change |
Ping.. |
I'll get a reviewer to look at it Monday. Meanwhile, can you please add a test to avoid regressions and a notice in the API docs? |
@juandopazo Ok,I will make it later . Thx ! |
I don't see what value a notice to the API documentation would add in this case. It seems unusual and unnecessary to let the developer know about the deprecation of An additional unit test also seems unnecessary. All in all, what we we really care about is whether or not Ping @lsmith. |
@@ -198,7 +198,9 @@ Y.extend(DOMEventFacade, Object, { | |||
preventDefault: function(returnValue) { | |||
var e = this._event; | |||
e.preventDefault(); | |||
e.returnValue = returnValue || false; | |||
if (e.type === 'beforeunload') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous assignment was simpler because it was harmless. It is still harmless (a warning is a minor nuisance, but not harmful).
I would prefer to keep the logic simpler and go with
if (returnValue) {
e.returnValue = returnValue;
}
And let the browser complain when a developer writes dubious code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a much better way and also avoid hardcode.
@ezequiel re: test coverage, sadly there are no tests of It is worth adding a test for |
@lsmith Sorry, I don't quite understand your meaning by |
Weird. the commit wasn't showing on the PR for me, but now it is. My mistake. |
@@ -158,7 +158,9 @@ Y.extend(DOMEventFacade, Object, { | |||
preventDefault: function(returnValue) { | |||
var e = this._event; | |||
e.preventDefault(); | |||
e.returnValue = returnValue || false; | |||
if (returnValue) { | |||
e.returnValue = returnValue || false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The || false
is unnecessary.
I'm ok with merging this even without new tests because the change in code functionality is obvious. The case where code is relying on 👍 |
@lsmith Something wrong, I will close this and made another PR |
As @hatched reported in #1417
chrome now issues a console warning
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.