-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Event: Fix handling of multiple async focus events #4354
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
Event: Fix handling of multiple async focus events #4354
Conversation
```
raw gz Compared to last run
-6 -5 dist/jquery.js
-2 +4 dist/jquery.min.js
```
mgol
left a comment
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.
Nice work! I left some comments but nothing blocking a merge of this.
src/event.js
Outdated
|
|
||
| // ...and capture the result | ||
| dataPriv.set( this, type, jQuery.event.trigger( | ||
| dataPriv.set( this, type, { value: jQuery.event.trigger( |
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.
Is the change to an object with the value field meant to distinguish the saved object from arguments saved before? Do I understand it right?
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.
Yes, exactly.
timmywil
left a comment
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.
Thanks for getting a PR in so quickly.
|
We'll want to cherry-pick that to master as well. |
| if ( !saved ) { | ||
| // Saved data should be false in such cases, but might be a leftover capture object | ||
| // from an async native handler (gh-4350) | ||
| if ( !saved.length ) { |
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.
wouldn't this break in case saved is false (set in dataPriv.set( this, type, false ); on line 570) ?
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.
@stof No, it works:
var b = false;
!b.length; // trueThis is because for a boolean b b.length will auto-box b into a Boolean instance and then check the length field on it which doesn't exist so b.length will evaluate to undefined. A negation of undefined is true.
I know it's not the most readable code but we care about size and this behavior is covered by tests.
because of jquery/jquery#4350 . This commit should be undone when jquery/jquery#4354 has made it into the latest version of jquery (probably jquery version 3.4.1)
because of jquery/jquery#4350 . This commit should be undone when jquery/jquery#4354 has made it into the latest version of jquery (probably jquery version 3.4.1)
Summary
Prevent leftover saved data from async focus/blur from overriding outermost trigger handling.
Fixes gh-4350
Checklist
If needed, a docs issue/PR was created at https://github.com/jquery/api.jquery.com