Focusout event on $(window) & $(document) : events call twice #4652
Comments
|
Thanks for the report. To add to that, on Firefox if I focus the input & then either focus another application or Firefox DevTools, I see 4 occurrences of the document focusout & 5 of window focusout. I initially thought it's related to the big refactor of focus event handling in #4279 but the issue is even in 3.0.0. |
in 2.2.4 too ! |
|
OK, so this issue first occurred in jQuery 1.11.0/2.1.0. It was working fine in 2.0.3. It was introduced in 1cecf64. That commit broke The issue doesn't exist on Taking into account that:
If you find a simple patch fixing the current 3.x implementation, we'd review the PR, though. Marking for discussion at today's team meeting. |
|
Oh, actually this is pretty simple: the That also explains why this was unreported so long - the issue happens only if you attach the |
|
PR: #4656 |
The `doc` variable in: https://github.com/jquery/jquery/blob/3.4.1/src/event/focusin.js#L30 matched `document` for `document` & `window` for `window`, creating two separate wrapper event handlers & calling handlers twice if at least one `focusout` or `focusin` handler was attached on *both* `window` & `document`, or on `window` & another regular node. Also, fix the "focusin from an iframe" test to actually verify the behavior from commit 1cecf64 - the commit that introduced the regression - to make sure we don't regress on either front. Fixes gh-4652 Closes gh-4656
Backport tests from a jQuery 3.x fix that's not needed on `master`. Also, fix the "focusin from an iframe" test to actually verify the behavior from commit 1cecf64 - the commit that introduced the regression - to make sure we don't regress on either front. The main part of the modified test was checking that focusin handling in an iframe works and that's still checked. The test was also checking that it doesn't propagate to the parent document, though, and, apparently, in IE it does. This one test is now blacklisted in IE. (cherry picked from 9e15d6b) (cherry picked from 1a4f10d) Ref jquerygh-4652 Ref jquerygh-4656
Backport tests from a jQuery 3.x fix that's not needed on `master`. Also, fix the "focusin from an iframe" test to actually verify the behavior from commit 1cecf64 - the commit that introduced the regression - to make sure we don't regress on either front. The main part of the modified test was checking that focusin handling in an iframe works and that's still checked. The test was also checking that it doesn't propagate to the parent document, though, and, apparently, in IE it does. This one test is now blacklisted in IE. (cherry picked from 9e15d6b) (cherry picked from 1a4f10d) Ref gh-4652 Ref gh-4656 Closes gh-4657
Description
If I attach
focusoutevent on the$(window)and$(document), each events are called twice.I use jQuery v3.4.1 and I have the same problem with Firefox (v74.0.1) and Chrome (v80.0.3987.163).
If I use native Js, each events are called once.
Link to test case
https://jsbin.com/rilamarodi/1/edit?html,css,js,output
open console, focus input field and go out (remove focus) to see on console that each events are called twice.
The text was updated successfully, but these errors were encountered: