googlearchive / firebase-util

An experimental toolset for Firebase
http://firebase.github.io/firebase-util
MIT License
276 stars 67 forks source link

$remove on a NormalizedCollection throws an Exception #90

Open apptimise opened 8 years ago

apptimise commented 8 years ago

I have a service with the following function:

 this.getRequested = function (uid) {
        var ref = new Firebase(FBURL);
        var refSearch = ref.child('profiles/' + uid + '/friends/requested');
        ///*
        var refSearch = new Firebase.util.NormalizedCollection(
            [ref.child('profiles/' + uid + '/friends/requested'), "frId"],
            [ref.child('users'), 'users', 'frId.username']
        ).select('frId.username', 'frId.status', 'users.img', 'users.uid').ref();
        //*/
        return $firebaseArray(refSearch);
}

After binding this to a $scope variable: $scope.frRequested = Friends.getRequested(authData.uid);

Now if I remove a record as follows: $scope.frRequested.$remove(friend);

I get the following WARNING:

FIREBASE WARNING: Exception was thrown by user callback. TypeError: Cannot read property 'ref' of null
    at Object.i.update (https://cdn.firebase.com/libs/firebase-util/0.2.5/firebase-util.min.js:9:22050)
    at https://cdn.firebase.com/libs/firebase-util/0.2.5/firebase-util.min.js:9:18061
    at https://cdn.firebase.com/js/client/2.4.2/firebase.js:203:710
    at gc (https://cdn.firebase.com/js/client/2.4.2/firebase.js:52:165)
    at cc (https://cdn.firebase.com/js/client/2.4.2/firebase.js:30:216)
    at dc (https://cdn.firebase.com/js/client/2.4.2/firebase.js:29:1259)
    at Ji.h.Ob (https://cdn.firebase.com/js/client/2.4.2/firebase.js:223:440)
    at X.set (https://cdn.firebase.com/js/client/2.4.2/firebase.js:259:335)
    at X.remove (https://cdn.firebase.com/js/client/2.4.2/firebase.js:262:146)
    at https://cdn.firebase.com/libs/firebase-util/0.2.5/firebase-util.min.js:9:19948 
firebase.js:52 Uncaught TypeError: Cannot read property 'ref' of null

I have tried a similar situation without using the NormalizedCollection, and everything works fine, i.e. when the service is as follow, it works without a problem:

 this.getRequested = function (uid) {
        var ref = new Firebase(FBURL);
        var refSearch = ref.child('profiles/' + uid + '/friends/requested');
        return $firebaseArray(refSearch);
 }

Is this a bug?

katowulf commented 8 years ago

Hello! Please use the non minimized versions of the libs (firebase-debug.js and firebase-util.js) and make sure you're on the latest versions. Update the stack trace with the non-minified versions. Provide a working, minimal repro or submit a PR with a failing test case.

haydermabood commented 8 years ago

Any updates on this, I am facing the same situation here, just try removing an item, and you will get an exception. I think this is a very critical bug. Please help.

Its happening at Record.js in the following function:

update: function(pathName, snap) { this.snaps[pathName] = snap; this._checkLoadState(); util.log('Record.ValueEventManager.update: url=%s, loadCompleted=%s', snap.ref().toString(), this.loadCompleted); if( this.loadCompleted ) { this.rec.trigger(new SnapshotFactory('value', this.rec.getName(), util.toArray(this.snaps))); } },

snap value is null.

FIREBASE WARNING: Exception was thrown by user callback. TypeError: Cannot read property 'ref' of null

Surrounding the function code with if(snap){...} seems to silence the problem, but I don't know if it solves it.