Open mgol opened 1 month ago
I'm referring to #5236 here as this PR essentially reverts that one (with added tests). The rationale for simplifying the check in #5236 was valid, it's just that we now have a second case where it's needed.
@timmywil @gibson042 PR updated & ready for another review.
main @399a78ee9fc5802509df462a2851aef1b60b7fbc
raw gz Filename
+31 +12 dist/jquery.min.js
+31 +14 dist/jquery.slim.min.js
+31 +13 dist-module/jquery.module.min.js
+31 +13 dist-module/jquery.slim.module.min.js
Summary
In Firefox, alert displayed just before blurring an element dispatches the native blur event twice which tripped the jQuery logic if a jQuery blur handler was not attached before the trigger call.
This was because the
leverageNative
logic part for triggering first checked if setup was done before (which, for example, is done if a jQuery handler was registered before for this element+event pair) and - if it was not - added a dummy handler that just returnedtrue
. TheleverageNative
logic made thattrue
then saved into private data, replacing the previoussaved
array. Sincetrue
passed the truthy check, the second native inner handler treatedtrue
as an array, crashing on theslice
call.The same issue could happen if a handler returning
true
is attached before triggering. A barelength
check would not be enough as the user handler may return an array-like as well. To remove this potential data shape clash, capture the inner result in an object with avalue
property instead of saving it directly.Since it's impossible to call
alert()
in unit tests, simulate the issue by replacing theaddEventListener
method on a test button with a version that calls attached blur handlers twice.Fixes gh-5459 Ref gh-5236
Checklist
If needed, a docs issue/PR was created at https://github.com/jquery/api.jquery.com