-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Watch File on Safari causes infinite $digest loop #10524
Comments
this boils down to two parts:
I think that @petebacondarwin how do you feel about making the change to |
Some background on why this happens: File (and many others) are what used to be called host objects, parts of the platform mainly implemented in C++ --- they have JS bindings automatically generated from IDL files, like this https://github.com/WebKit/webkit/blob/master/Source/WebCore/fileapi/File.idl Those properties are defined as accessors, and they'll try to invoke the accessors implemented in C++ --- the problem is that So we aren't going to construct that host object with A good idea is to just not deep-watch host objects if you want to make sure Safari doesn't explode :( |
How does this fare with |
@petebacondarwin everybody is happy is |
$watchCollection doesn't really make sense here |
@caitp why do you think it does not make sense to use |
because it's very different, semantically |
I think that everybody knows that Is this what you mean when you say that they are semantically different? Now, the question is if we should solve this or not. If we should solve this then how, and if not then what are the possible work-arounds. The one solution I can think of (without adding special rules for host objects) is #10524 (comment). This is not perfect and for sure it is not for free. If we are not going to solve this then we have to be clear that Safari does not behave well when you are deep watching a host object, and have solution for the community to use. In this case, using |
semantically different means exactly what it sounds like, the semantics of the two functions are different, and are not interchangeable. This isn't a real workaround, because it will only work under certain conditions (when array or object valued properties aren't considered, and when the prototype chain of the object being watched doesn't matter). Beyond that, you're telling people to write text which does not represent their intentions, or the actions they're actually performing, which is always a bad recipe. Unfortunately, there isn't much we can do about it. Fixing one use-case harms other use cases. There are other solutions, which are a bit more complicated, but work better. You can watch the specific properties you care about. If you need to watch multiple properties, you can use |
It seems that this issue is a corner case that has a couple of workarounds: i.e. to use |
A suitable workaround for something like this is to do $scope.$watch(() => scope.file && scope.file.name, (fileName) => ...) IMO this can probably be closed. |
Yes, I agree this is a very uncommon scenario with a number of workarounds, so no need to change the core for this. |
Hi,
On Safari with angular 1.3, watching changes on a JavaScript File object throws:
and causes a infinite $digest loop.
Reproducable here:
http://jsbin.com/vaketipeyo/1/edit?js,console,output
Choosing a file will produce the error
Angular version: > 1.3
My config:
Browser: safari 8.0.2
OS: OS X 10.10.1
This issue might be related to: #10370 #10210
The text was updated successfully, but these errors were encountered: