-
Notifications
You must be signed in to change notification settings - Fork 20.6k
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
Exception when element is removed on blur #4417
Comments
Thanks for the report! We advise JS Bin for creating test cases as JSFiddle no longer supports IE; you control the whole HTML there. But even in JSFiddle you can attach a proper jQuery version by uploading a script or adding a script tag in HTML. So please still add a test case. Thanks! |
Here's a jsbin link; Note that the problem occurs on Chrome, not on Firefox. It is timing/sequence-related. |
This is an unusual case, but valid. I think we want to replace |
As I understand it, this is a regression so we should include it in |
In Chrome, if an element having a focusout handler is blurred by clicking outside of it, it invokes the handler synchronously. If that handler calls `.remove()` on the element, the data is cleared, leaving private data undefined. We're reading a property from that data so we need to guard against this. Fixes jquerygh-4417
PR: #4799 |
In Chrome, if an element having a `focusout` handler is blurred by clicking outside of it, it invokes the handler synchronously. If that handler calls `.remove()` on the element, the data is cleared, leaving private data undefined. We're reading a property from that data so we need to guard against this. Fixes gh-4417 Closes gh-4799
In Chrome, if an element having a `focusout` handler is blurred by clicking outside of it, it invokes the handler synchronously. If that handler calls `.remove()` on the element, the data is cleared, leaving private data undefined. We're reading a property from that data so we need to guard against this. Fixes gh-4417 Closes gh-4799 (cherry picked from commit 5c2d087)
Description
Running Chrome 73.0.3683.86 on Windows 7 with jQuery 3.4.1.
jQuery tries to read a property of an undefined, causing an exception. This occurs when an element is removed when it loses focus, during a focusout handler, responding to a jQuery triggered blur() event. The three key operations are all performed via jQuery:$(element).blur(), $ (element).on("focusout"), $(element).remove().
The exception occurs on line 5467; here is the code up to that line:
In the last line, result is undefined. That is because during
this[ type ]()
(which issues the event), the element is removed, causing jQuery to remove its saved information from dataPriv in cleanData() line 6046:elem[ dataPriv.expando ] = undefined;
Thus, after
this[ type ]()
, result is undefined, it does not equal saved, so thedataPriv.set()
of the conditional is executed and result is left undefined. Presumably,result = ()
needs to be set outside the conditional. This problem is also timing-sensitive -- with the certain break points it may not occur.This didn't happen in 3.3.1. Note also that jQuery's
blur()
must be used, rather than normal JSblur()
, in order to go through this code path.Link to test case
jsfiddle uses 3.3.1, so I didn't set up a test case.
*EDIT by @mgol: I wrapped code pieces in backticks to fix Markdown formatting
The text was updated successfully, but these errors were encountered: