-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Illegal Invocation / Infinite Digest on deep $watch if a property is a DOM or jQuery object. #11001
Comments
I do not know what you are trying to do, but watching DOM elements/jQuery elements is not something planned to be supported any time soon |
Not to mention horrible performance implications of doing so.... It would be interesting to understand what is going on, though. But yeh, we should actively discourage people from watching DOM objects and their properties as part of the digest loop. |
I'm not trying to watch a DOM object and I agree with both of your comments. I noticed this bug with angular-ui-sortable. This module does a deep watch on its sortOptions which can contain a DOM/jQuery object. The intention isn't to watch the DOM object itself but it gets scooped into the deep watch just the same, causing the infinite loop and illegal invocation errors. Here is my bug on that project: angular-ui/ui-sortable#330 I dug deeper into the problem and found I could replicate it with vanilla angular.js so the bug wasn't in ui-sortable but in angular. The problem is caused by the deep watch doing an angular.copy on the scope object, which attempts to do a deep copy of the DOM object. I don't think this is intended functionality and angular.copy should not attempt to copy DOM objects. Here is my pull request: #11006 |
Hi, Sorry, I just do not agree with this issue nor with the solution provided at #11006. In fact, the only real solution would be that if any DOM element goes into This will be a breaking change, so can not happen in a point release. @petebacondarwin WDYT? |
My PR does throw if any DOM element goes into copy. The other side of this is if you're doing a deep watch on any object if it finds a DOM/jQuery object in that object it will not attempt to copy it. I don't think this is a breaking change. If anyone has done a copy or deep watch on an object containing a DOM object their application is already broken. |
I think we're in agreement, maybe I'm not explaining correctly.
|
Hi, the PR allows this to be valid and not throw it("should not throw an exception if a copied object contains a DOM and/or Element.", function() {
var src = {a: document.body, b: angular.element(document.body)};
var dst = {};
expect(function() { copy(src, dst); }).not.toThrow();
}); and it should throw. Anything that is part of the DOM should never go into a $watch |
It copies There is valid cases for having a DOM object on an object being watched though. |
@iamchairs this looks simply wrong, deep watching on any structure that ends up in a DOM should be illegal. In this specific case, the right solution is to use |
Then there needs to be an update to throw when this happens. Otherwise, illegal invocation, infinite digest, browser crashes. |
and I would be ok with a change to |
You can close this out. No need to update my PR because this doesn't solve my problem. Back to angular-ui-sortable! |
Example JSBin:
http://jsbin.com/favorinava/6/edit
Steps to reproduce:
The text was updated successfully, but these errors were encountered: