Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating nested item duplicates items in list. #800

Closed
leandroz opened this issue Jan 30, 2017 · 9 comments
Closed

Updating nested item duplicates items in list. #800

leandroz opened this issue Jan 30, 2017 · 9 comments

Comments

@leandroz
Copy link

Version info

Angular: "2.2.1"

Firebase: "^3.6.6"

AngularFire: "^2.0.0-beta.7"

Other (e.g. Ionic/Cordova, Node, browser, operating system): Ionic: "^2.0.0" in iOS device.

How to reproduce these conditions

Steps to set up and reproduce

Basically I have a list of users with information like:

users: {
  uid: {
    displayName,
    ...etc
  }
}

Then I have 2 subscriptions:

let currentUserRef = this.af.database.object(`/users/${state.uid}`);
let allUsersRef = this.af.database.list(`/users`);

Everytime I do an update like this:

let currentUserRef = this.af.database.object(`/users/${uid}`);
currentUserRef.update(data);

A record is duplicated in the listener of the allUsersRef observable.
In this case I have 3 users and after doing 3 updates the 2 of them that are not the current user get duplicated (one 2 times and the other 3 times)

Sample data and security rules

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null",
   	"users": {
      "$uid": {
        ".indexOn": ["email", "displayName"]
      },
      "public": {  ".read": true },
      "private": {
      	"$uid": {
      		".read": "auth.uid === $uid"
    		}
    	}
  	}   
  }
}

Debug output

** Errors in the JavaScript console **

** Output from firebase.database().enableLogging(true); **

** Screenshots **
web inspector denise s ipad vaqapp index html 2017-01-29 21-46-41

Expected behavior

Get only 3 users without duplicates.

Actual behavior

Got 6 users with duplicates.

@leandroz
Copy link
Author

It happens in Chrome (browser) too.

@davideast
Copy link
Member

@leandroz Can you create a plnkr with some steps so I can debug?

@cartant
Copy link
Contributor

cartant commented Jan 31, 2017

@leandroz There's a plunk here if you want to fork it to create a repro of the bug. I had a quick look to see if it was something that would affect me, but couldn't reproduce it. The code's in app/app.component.ts

@leandroz
Copy link
Author

@davideast @cartant thanks both, I will do it now.

@leandroz
Copy link
Author

I am getting an error trying with firebase 3.6.6, https://plnkr.co/edit/12sFkTKA2fLCp6m4prw9?p=preview

@cartant
Copy link
Contributor

cartant commented Feb 1, 2017

@leandroz There is a SystemJS issue with versions of Firebase more recent than 3.4.0 and AngularFire2. It's mentioned in this issue and there's a related SO question, too.

I've updated the plunk with this workaround and it now works with Firebase 3.6.7, so you might want to fork it again.

@leandroz
Copy link
Author

leandroz commented Feb 1, 2017

@cartant thanks for the help, here you have the plunk with some changes, https://plnkr.co/edit/CDiApWr7r1JnqzcGwLaA?p=preview, I couldn't reproduce exactly the duplication, but here you will see that one subscription to all the users gets only 1 and not the 3 users, I am pretty sure is related.

@cartant
Copy link
Contributor

cartant commented Feb 1, 2017

@leandroz There are a couple of uses of issue-80/ in paths in that plunk that should be issue-800/. If they are corrected, it appears to behave as I'd expect it to.

@leandroz
Copy link
Author

leandroz commented Feb 2, 2017

@cartant stupid mistake, I cannot reproduce this, I will try to debug in my app and see what I can find, closing until then.

@leandroz leandroz closed this as completed Feb 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants