angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

(iOS 8 GM iPhone5C) TypeError: Attempted to assign to readonly property

Open HAKASHUN opened this issue 12 years ago • 163 comments

I am using on iOS 8 GM(iPhone5C). With this device, I am getting this error in this line(https://github.com/angular/angular.js/blob/master/src/ng/rootScope.js#L216) But on iOS 8 GM(iPhone5S) and iOS 7.x (iPhone5C, iPhone5S), this error does not occur.

To resolve this error, I rewrote the code as follows:

$new: function(isolate) {
        var child;

        if (isolate) {
          child = new Scope();
          child.$root = this.$root;
          // ensure that there is just one async queue per $rootScope and its children
          child.$$asyncQueue = this.$$asyncQueue;
          child.$$postDigestQueue = this.$$postDigestQueue;
        } else {
          // Only create a child scope class if somebody asks for one,
          // but cache it to allow the VM to optimize lookups.
          if (!this.$$ChildScope) {
            this.$$ChildScope = function ChildScope() {
              this['$$watchers'] = this['$$nextSibling'] =
                  this['$$childHead'] = this['$$childTail'] = null;
              this['$$listeners'] = {};
              this['$$listenerCount'] = {};
              this['$id'] = nextUid();
              this['$$ChildScope'] = null;
            };
            this.$$ChildScope.prototype = this;
          }
          child = new this.$$ChildScope();
        }
        child['this'] = child;
        child['$parent'] = this;
        child['$$prevSibling'] = this.$$childTail;
        if (this.$$childHead) {
          this.$$childTail.$$nextSibling = child;
          this.$$childTail = child;
        } else {
          this.$$childHead = this.$$childTail = child;
        }
        return child;
      },

The situation has improved, but I do not understand the reason...

HAKASHUN avatar Sep 17 '14 13:09 HAKASHUN

This is obviously a problem for a lot of people. The fact that it is not reproducible in a controlled environment does in my opinion not preclude any fixes for the given problem to be implemented. As it seems, there is a monkey-patch available that fixes the problem. If said monkey-patch does not cause any other verifiable problems (in unit tests etc.) I don't really understand the reasoning behind not applying it and fixing the problem for everyone.

asbjornu avatar Apr 07 '15 11:04 asbjornu

If said monkey-patch does not cause any other verifiable problems (in unit tests etc.) I don't really understand the reasoning behind not applying it and fixing the problem for everyone.

send a PR =)

caitp avatar Apr 08 '15 14:04 caitp

@caitp wrote:

send a PR =)

I'd prefer if @jhunken as the author of said monkey patch could do it. :)

asbjornu avatar Apr 09 '15 10:04 asbjornu

@asbjornu I've been lucky enough to benefit from jhunken's patch but in my use case the monkey patch has not worked after minification. If my problem is the same problem other people have; accepting this patch won't necessarily fix anything.

If I can get the go ahead to publish our demo, then we should be able to reproduce on other devices. This might not be for another month though. There is also the chance that the recent iOS 8.3 release has fixed this problem, but I haven't had a chance to test yet.

bennett000 avatar Apr 11 '15 22:04 bennett000

Hi, @spencerwi , have you figured out why the "undefined" word appears when applying the patch? Have you found any other workaround? Thanks

RosanaRufer avatar Apr 12 '15 13:04 RosanaRufer

@totemika @spencerwi from our side we just get rid of the "undefined" by changing the way we are using translate, e.g.

it was not working using:

<h2 translate="'GETTING_STARTED_HEADLINE"></h2>

It works with:

<h2>{{ 'GETTING_STARTED_HEADLINE' | translate }}</h2>

brauliodiez avatar Apr 12 '15 17:04 brauliodiez

@brauliodiez @spencerwi That totally worked :+1:

RosanaRufer avatar Apr 13 '15 06:04 RosanaRufer

@bennett000 btw - I've just upgraded to iOS 8.3 and I can confirm that I'm still getting this issue.

To be clear, I get it with or without the monkey patch on an iPad 4G (2012) running both iOS 8.3 and iOS 8.1.3. It's not always reproducible - sometimes just attaching it to a Safari debugger running on a Mac fixes it, but then other times it still goes wrong when attached (which at least allows me to read the exception trace).

duncangrist avatar Apr 24 '15 10:04 duncangrist

Are you using angular translate?

brauliodiez avatar Apr 24 '15 11:04 brauliodiez

@brauliodiez - I am using angular-translate yes - and angular-ui-router which is actually in the stack trace below.

angular#1.3.15
angular-translate#2.4.2
angular-ui-router#0.2.13
Error: Attempted to assign to readonly property.
ChildScope@http://<hostname_redacted>/2/vendor/angular/angular.js:13617:34
$new@http://<hostname_redacted>/2/vendor/angular/angular.js:13759:40
compositeLinkFn@http://<hostname_redacted>/2/vendor/angular/angular.js:7096:38
nodeLinkFn@http://<hostname_redacted>/2/vendor/angular/angular.js:7763:35
compositeLinkFn@http://<hostname_redacted>/2/vendor/angular/angular.js:7117:23
compositeLinkFn@http://<hostname_redacted>/2/vendor/angular/angular.js:7120:24
compositeLinkFn@http://<hostname_redacted>/2/vendor/angular/angular.js:7120:24
nodeLinkFn@http://<hostname_redacted>/2/vendor/angular/angular.js:7763:35
compositeLinkFn@http://<hostname_redacted>/2/vendor/angular/angular.js:7117:23
compositeLinkFn@http://<hostname_redacted>/2/vendor/angular/angular.js:7120:24
publicLinkFn@http://<hostname_redacted>/2/vendor/angular/angular.js:6996:45
http://<hostname_redacted>/2/vendor/angular-ui-router/release/angular-ui-router.js:3905:13
invokeLinkFn@http://<hostname_redacted>/2/vendor/angular/angular.js:8258:15
nodeLinkFn@http://<hostname_redacted>/2/vendor/angular/angular.js:7768:23
compositeLinkFn@http://<hostname_redacted>/2/vendor/angular/angular.js:7117:23
publicLinkFn@http://<hostname_redacted>/2/vendor/angular/angular.js:6996:45
updateView@http://<hostname_redacted>/2/vendor/angular-ui-router/release/angular-ui-router.js:3839:34
http://<hostname_redacted>/2/vendor/angular-ui-router/release/angular-ui-router.js:3801:21
$broadcast@http://<hostname_redacted>/2/vendor/angular/angular.js:14785:33
http://<hostname_redacted>/2/vendor/angular-ui-router/release/angular-ui-router.js:3218:32
processQueue@http://<hostname_redacted>/2/vendor/angular/angular.js:13248:29
http://<hostname_redacted>/2/vendor/angular/angular.js:13264:39
$eval@http://<hostname_redacted>/2/vendor/angular/angular.js:14466:28
$digest@http://<hostname_redacted>/2/vendor/angular/angular.js:14282:36
$apply@http://<hostname_redacted>/2/vendor/angular/angular.js:14571:31
done@http://<hostname_redacted>/2/vendor/angular/angular.js:9698:53
completeRequest@http://<hostname_redacted>/2/vendor/angular/angular.js:9888:15
requestLoaded@http://<hostname_redacted>/2/vendor/angular/angular.js:9829:24 <div ui-view="main" class="ng-scope">

Edit: Just upgraded to angular-ui-router#0.2.14, angular-translate#2.6.1 and the problem remains.

duncangrist avatar Apr 24 '15 11:04 duncangrist

@pascalc On removing 'use strict', I also see the browser hanging after 5-10 mins. angularjs-1.3.15, ios-8.3, iPad-2, ui-router-0.2.13

Any other workarounds that solved this problem for you? Any help would be much appreciated.

Webkit issue for the same https://bugs.webkit.org/show_bug.cgi?id=49739

bewithjonam avatar Apr 28 '15 13:04 bewithjonam

I use angular material and getting the same "Error: Attempted to assign to readonly property." almost always on my 8.3 iOS iPad (first retina). Monkey patch does not solve the problem for me. Also deleting "use strict" in angular and angular-material makes everything worse. There are no error messages in safari remote debugger anymore but the page loads only in parts - from ng-repeat half of the items are randomly displayed correct, other half is shown with {{...}} as plain text.

Maybe somebody can use my testcase http://v2.atocc.de/testcase just click on "öffnen" of one of the listed diagrams on an iPad - I always get 4x"Error: Attempted to assign to readonly property." in about 80% of my many reloads / tries - but still sometimes it works. The testcase works fine on desktop browsers. I have another angular-material app without any problem so I can't simplify the testcase.

gitmh avatar Apr 29 '15 21:04 gitmh

@gitmh thanks for the reproduction, taking a look on my ipad =)

This has been extremely frustrating to track down, I'm sorry for everyone having issues supporting iOS devices due to this problem :(

caitp avatar Apr 29 '15 21:04 caitp

@gitmh I've been trying for a while, but I can't seem to reproduce this on an iPad (MD787C/A) with iOS 8.3 --- Method: Press on "öffnen" buttons on random graphs (whether same button is pressed sequentially or not doesn't seem to have an impact).

If any WebKit/JSC gurus know if there are any flags to force (different types of) optimization of even cold code, that might be helpful in tracking this down.

caitp avatar Apr 29 '15 21:04 caitp

@gitmh I'm getting the "Attempted to assign to readonly property" error about every other time I click on offnen with iPad 2 simulator iOS 8.3 (12F69).

I'm having the same issue in my Angular application :(

joshuajohnson814 avatar Apr 30 '15 01:04 joshuajohnson814

For me this looks like a timing issue on the iPad - my example is loading a diagram with multiple small parts with lot's of ng-bindings. A small diagram works better - lets say 30% of the time and a large diagram only 5% of my tries. The result for the user is an empty diagram panel on the right side of the window. Seldom also the starting page of the testcase shows only some cards with "öffnen" buttons - so material buttons seems to be a good example for reproduction. I made other copys like http://v2.atocc.de/testcase2 where I deleted "use strict" in angluar, angular-route, angular-material and angular-aria. This makes the whole app unuseable but no error messages in safari. Added another http://v2.atocc.de/testcase3 without use of jquery to make sure it's not a problem with it. http://v2.atocc.de/testcase4 without jquery but with "use strict". I also disabled any caching with headers so on each testcase the title should change to TESTCASE n.

gitmh avatar Apr 30 '15 06:04 gitmh

@gitmh I agree, timing/load seems to be the trigger. In my application, I don't see this error until I stress the CPU. Other conditions mentioned in this thread (iOS version, translate, etc) do not seem to be related as I have seen it on iPad mini, iPad air 2, iPhone 5s, and the simulator on every 8.x version of iOS and also in cordova using UIWebView and WKWebView. I have no log of it happening on any device since removing 'use strict'. It also explains why it is so damn hard to reproduce.

gdjennings avatar Apr 30 '15 07:04 gdjennings

I added another testcase http://v2.atocc.de/testcase5 with the monkey patch from @jhunken it works much better but still sometimes the app breaks without error message. The "Error: Attempted to assign to readonly property." messages disappeared now.

gitmh avatar Apr 30 '15 07:04 gitmh

+1 Bumped into the same as everyone describe.

  1. I can confirm the error using @gitmh testcase on my test iPad MD328FD/A with iOS 8.3
  2. My app is consistently hitting this issue. but it's in private-beta, shareable only via PM.
  3. I use some of the same dependencies others mention: angular#1.3.15, angular-ui-router#0.2.14, angular-translate#2.4.2
  4. Removing "use strict" makes safari hang as @pascalc and @bewithjonam mention

oori avatar May 01 '15 23:05 oori

+1 also, I'm getting this on multiple iphones/ipads all running some version of iOS 8 2 hours before the first occurence was reported, I merged this in my bower.json (no issue whatsoever before this merge, and no other merge were done that day)

-    "ngCordova": "0.1.14-alpha",
-    "ionic": "1.0.0-rc.3",
-    "mapbox.js": "2.1.6",
+    "ngCordova": "0.1.15-alpha",
+    "ionic": "1.0.0-rc.4",
+    "mapbox.js": "2.1.8",

Here are the full dependencies:

  "dependencies": {
    "ngCordova": "0.1.15-alpha",
    "ionic": "1.0.0-rc.4",
    "angular-animate": "1.3.15",
    "angular-sanitize": "1.3.15",
    "mapbox.js": "2.1.8",
    "leaflet": "0.7.3",
    "rollbar.js": "1.2.1"
  },
  "resolutions": {
    "angular": "1.3.15",
    "angular-animate": "1.3.15",
    "angular-sanitize": "1.3.15"
  }

adrienkohlbecker avatar May 10 '15 22:05 adrienkohlbecker