You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
fix(jqLite.cleanData): TypeError: Cannot read property 'events' of undefined #16641
Anything else:
TypeError: Cannot read property 'events' of undefined
at Function.jqLite.cleanData (angular.js:2051)
at replaceWith (angular.js:10704)
at applyDirectivesToNode (angular.js:9768)
at compileNodes (angular.js:9293)
at compileNodes (angular.js:9305)
at compileNodes (angular.js:9305)
at compileNodes (angular.js:9305)
at compile (angular.js:9174)
at Object.link (angular.js:28966)
at angular.js:1364
This is so wrong. It for years worked correctly elem._data('events') and recently was changed to incorrect elem._data().events with no obvious for me reason
Hm...OK if we can fix this is a non-breaking way, then there is little reason not to, I guess 😃
It was changed in b7d396b. @mgol, any objection against reverting jqLite._data(elem).events to jqLite._data(elem, 'events')? Is this going to affect the behavior with latest jQuery?
@alextkachman AngularJS hasn't supported jQuery 1.x since version 1.3 if I remember correctly. This version was released almost 4 years ago. Your configuration has been unsupported for a long time so something may randomly break even in a patch release; we can't prevent that from happening as we don't run unit tests with jQuery 1.x. You should move to a supported version of jQuery, i.e. 2.1 or newer.
@gkalpak We can't just revert the change as jqLite doesn't support the two-param _data signature and the linked commit changed the cleanData patch to be performed on jqLite in addition to jQuery. That's why I changed this line.
Fixing this issue requires to do one of the following:
fork the logic inside of the patch for jQuery & jqLite
add support for the two-param _data to jqLite
add a check for jQuery._data(elem) being defined before accessing its events property
I think what happens is jQuery 1.x uses jQuery.cleanData inside jQuery#remove internally where it removes the cache entry for the removed node before calling jQuery.cleanData, making jQuery._data(elem) return undefined inside of our patched jQuery.cleanData. In all other cases, even jQuery 1.x should be falling back to an empty object if there are no handlers attached.
Activity
gkalpak commentedon Jul 22, 2018
This is a jQuery 1.x issue. Not sure which version it was fixed in, but jQuery 3.x (as well as AngularJS' built-in
jqLite) always return an object.alextkachman commentedon Jul 22, 2018
This is so wrong. It for years worked correctly elem._data('events') and recently was changed to incorrect elem._data().events with no obvious for me reason
gkalpak commentedon Jul 22, 2018
Hm...OK if we can fix this is a non-breaking way, then there is little reason not to, I guess 😃
It was changed in b7d396b.
@mgol, any objection against reverting
jqLite._data(elem).eventstojqLite._data(elem, 'events')? Is this going to affect the behavior with latest jQuery?mgol commentedon Jul 22, 2018
@alextkachman AngularJS hasn't supported jQuery 1.x since version 1.3 if I remember correctly. This version was released almost 4 years ago. Your configuration has been unsupported for a long time so something may randomly break even in a patch release; we can't prevent that from happening as we don't run unit tests with jQuery 1.x. You should move to a supported version of jQuery, i.e. 2.1 or newer.
@gkalpak We can't just revert the change as jqLite doesn't support the two-param
_datasignature and the linked commit changed thecleanDatapatch to be performed on jqLite in addition to jQuery. That's why I changed this line.Fixing this issue requires to do one of the following:
_datato jqLitejQuery._data(elem)being defined before accessing itseventspropertyI think what happens is jQuery 1.x uses
jQuery.cleanDatainsidejQuery#removeinternally where it removes the cache entry for the removed node before callingjQuery.cleanData, makingjQuery._data(elem)returnundefinedinside of our patchedjQuery.cleanData. In all other cases, even jQuery 1.x should be falling back to an empty object if there are no handlers attached.gkalpak commentedon Jul 22, 2018
Thx for the info, @mgol. Although jQuery 1.x is indeed not supported, I think option (3) is harmless (and straight forward). I'll submit a PR.
fix(cleanData): do not break if `jQuery._data()` returns undefined
fix(angular.element): do not break on `cleanData()` if `_data()` retu…
fix(angular.element): do not break on `cleanData()` if `_data()` retu…
mgol commentedon Jul 23, 2018
Yes, I forgot to add option 3 sounded the best to me as well as it's such a critical place and such an easy fix.
alextkachman commentedon Jul 23, 2018
Thank you, @gkalpak and @mgol