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

Which version of angular did you test? Does it appear simply by including angular or under specific circumstances (your app code)?

Narretz avatar Sep 17 '14 13:09 Narretz

I tested AngularJS v1.2.25.

My app code is below.

page template

...
<card-item-list ng-repeat="card in cards track by $index" data-card="card"></card-item-list>

card-item-list directive

...
var cardItemList = function() {
    var link = function(scope) {};
    return {
      restrict: 'E',
      replace: true,
      templateUrl: 'templates/card/directives/list-item.html',
      scope: {
        card: '=',
      },
      link: link
    };
  };
  cardItemList.$inject = [];
...
<div class="card--list__item">
  <div ng-class="{'card--list__item_state_check': card.isSelect}">
    <card-thumb data-card="card"></card-thumb>
  </div>
  <p class="card--list__item__detail fs_xxs">
    <span ng-if="card.parameter.attack > 0">{{card.parameter.attack}}<br>&nbsp</span>
    <span ng-if="card.parameter.defense > 0">{{card.parameter.defense}}<br>{{card.parameter.speed}}</span>
  </p>
</div>

card-thumb directive

...
var cardThumb = function() {
    return {
      restrict: 'E',
      replace: true,
      transclude: true,
      templateUrl: ''templates/card/directives/card-thumb.html',
      scope: {
        card: '=',
        opts: '=?'
      },
      link: function(scope, element){
      }
    };
  };
 cardThumb.$inject = [];
...
<figure class="thumb thumb_type_1">
  <img class="thumb__img" ng-src="{{card.image_path}}"  ng-if="card.master_id">
  <figcaption class="thumb__caption" ng-transclude></figcaption>
</figure>

HAKASHUN avatar Sep 17 '14 14:09 HAKASHUN

@christianv could you please put together a http://plnkr.co/ or http://jsbin.com/ to reproduce this?

I'll see if I can repro this on my ipad or iphone 6 (but, from what you said, it sounds like I might not be able to :()

caitp avatar Sep 26 '14 19:09 caitp

@caitp I think you meant to notify someone else.

christianvuerings avatar Sep 26 '14 19:09 christianvuerings

yeah I meant @HAKASHUN, sorry

caitp avatar Sep 26 '14 19:09 caitp

remove 'use strict' and try

disney007 avatar Oct 21 '14 08:10 disney007

we get the same issue, and @HAKASHUN's code fixed the issue for us

ssetem avatar Oct 31 '14 16:10 ssetem

We get the same issue.

I applied @HAKASHUN's code to v1.2.26

https://github.com/shunjikonishi/angular.js/commit/b91f34103974047708145e971506f354f804c17c

When I include angular.js, it works fine. But with angular.min.js, it doesn't work.

I hope to fix this problem with both of normal and minified version.

shunjikonishi avatar Nov 06 '14 08:11 shunjikonishi

We have also experienced this error with several different iPads, all running iOS 8. I can get exact model numbers if anybody is interested. We have tried builds with Angular versions: 1.2.24, 1.3.0, and 1.3.1

@HAKASHUN's fix has worked at least in debug (non-minified) builds.

@shunjikonishi this is just a guess (I'm dealing with the same issue) but does your minifier perhaps do something like forcing dot notation? That would effectively undo this fix. I've tried one minification with uglify (2.4) and it broke the fix, and now I'm looking into my guess. Perhaps I can ask uglify to respect dot notation, or maybe I'm way off.

update

Is anyone else using $route?

Also @shunjikonishi in my case, uglifyjs was forcing dot notation, effectively undoing the fix. If you're using grunt/uglify it's something like: uglify: { options: { properties: false }}

bennett000 avatar Nov 06 '14 16:11 bennett000

could you make a quick reproduction of this? I'd like to see it with my phone

caitp avatar Nov 06 '14 16:11 caitp

@caitp I will see what I can do. I've got some unexpected work to take care of, but this is important, so hopefully I will have a plunker by the afternoon.

update

@caitp I made a plunker to attempt to reproduce this issue, and failed.

If anyone is interested in looking at my plunker attempt at reproducing, it's here: http://plnkr.co/edit/EPsxhO1OsD5MmnUyl50t?p=preview I started with a simple click updating a $scope, then tried $route changes (which is where I can consistently reproduce in my app), and then tried repeats, and a repeat in an ng-if.

I will put more time into this later.

bennett000 avatar Nov 06 '14 16:11 bennett000

@bennett000 Thank you for advise.

I just used output of grunt package command.

Now, I include uglify angular task in my project. It works fine.

There is one correction. With grunt-contrib-uglify, its option format is like this.

uglify: {
    options: { 
        compress: {
            properties: false 
        }
    }
}

shunjikonishi avatar Nov 07 '14 02:11 shunjikonishi

This also appears to affect Angular v1.3.0; we've seen it on an iOS8 device in our office, but the page it's on hits the error inconsistently (something we're researching).

Applying @shunjikonishi 's patch causes the page not to break under those conditions, but also causes "undefined" to appear on the page in places it shouldn't, and not to be removed.

Perhaps not the most useful set of details, but this is the result of an initial investigation. We can dig deeper; just wanted to note that v1.3.0 is also affected.

spencerwi avatar Nov 07 '14 14:11 spencerwi

hey guys, we're still waiting for a reproduction =)

caitp avatar Nov 07 '14 14:11 caitp

(so please provide one)

caitp avatar Nov 07 '14 14:11 caitp

@caitp absolutely, reproducing the error consistently is essential.

What's odd is that I can reproduce this consistently in my application, as can others; yet I failed to reproduce in a plunker. I'm happy to keep working on reproducing this in an example, but I'd really like to get more details from other people who have this issue.

In our case:

  • Web app is "saved" to iOS home screen
  • Web app is run from iOS home screen
  • Web app breaks after a few $location.path() calls

iDevice model numbers known to be affected:

  • MD528C/A
  • MD516C/A
  • MF432C/A

I'm wondering if there is a difference if the application is run from the iOS home screen, as opposed to being run in iOS Safari, or in a WebView, or WKView; this has been the case in older iOS versions.

I will work more on a plunker, and I will also take the plunker code, and spin it into a self contained application so I can see if I can reproduce it when "saved" to the iOS home screen.

Again, any extra information anyone else has about their issues would be helpful.

update

Dropping the existing plunkr stuff I had done into a full blown iOS homescreen web app does not seem to have had any additional effect.

Is anyone else using any custom gestures, or doing anything special to avoid things like iOS's bounce scrolling?

bennett000 avatar Nov 07 '14 15:11 bennett000

Removing the 'use strict'; solve the issue for me (iPhone 5C iOS 8.1).

dmitriynosenko avatar Nov 20 '14 11:11 dmitriynosenko

Over the last few weeks I continued to fail to reproduce this problem in a controlled environment, like a plunkr. On top of that, other workarounds, including removing 'use strict' do not help me. Obviously without a controlled reproduction of this issue there's nowhere to begin solving this problem. However it occurred to me that Angular ships with its own unit test suite; how do those tests perform on my devices?

  • Angular.js commit: 9a616eade4386341e51f993fe8824840ea96a8e9
  • On Ubuntu 12.04, running Chromium 37.0.2062 all tests pass
  • On iOS 7.1.2, running mobile Safari 7.0.0, (Model MF432C/A) all tests pass
  • On iOS 8.1.1, running mobile Safari 8.0.0, (Model MD528C/A) one tests fails

Mobile Safari 8.0.0 (iOS 8.1.1) private mocks createMockStyleSheet should allow custom styles to be created and removed when the stylesheet is destroyed FAILED Expected '0px' to be '2px'. ~/Workspaces/angular.js/test/helpers/privateMocksSpec.js:23:47

My guess is that this failed test is unrelated.

Again, anyone with any suggestions on how to reproduce the iOS 8 readonly error would be helpful. I do know other frameworks have had similar issues with readonly property assignments in iOS8.x but they have not helped me reproduce. Here are the links that reference the similar issues some others have encountered

  • http://trackjs.com/blog/tracked-attempted-assign-readonly-property-ios-8-typeerror/
  • https://bugs.webkit.org/show_bug.cgi?id=138038
  • https://bugs.webkit.org/show_bug.cgi?id=49739

Other steps I've taken to mitigate this problem have been to comb over our entire source, and the source of every library we use to find anything that might set a property read only. This includes grepping for:

  • Object.create()
  • freeze
  • writable
  • configurable
  • defineProperty

Is there anything else that might make JavaScript throw a type error read only? Not being able to reproduce this is not helping my sanity.

bennett000 avatar Dec 03 '14 02:12 bennett000

We are also running into this. We were able to reproduce the problem only on the actual device (in our case IPhone 5C) with an IOS version prior to 8.1 (we're testing on 8.0.2 and the problem recurs continuously).

This is quite a serious issue, is there any known workaround?

(We're on Angular 1.3.6, updated today, problem still persists)

m3kka avatar Dec 09 '14 14:12 m3kka

@m3kka did you manage to isolate the problem? It will be very hard to move on this one without narrowing it down first.

pkozlowski-opensource avatar Dec 09 '14 14:12 pkozlowski-opensource