Records created with a previously deleted ID generates an uncaught error
See original GitHub issueIn my application, I have what I think is a fairly standard User
model, whose IDs are based on the authenticated users’ fbRef.getAuth().uid
value (which in my case is assigned by the Anonymous authentication provider). I have a global users which dynamically updates as users authenticate/unauthenticate, that is populated using a basic this.store.find('user')
call.
The problem arises when a user signs out, and then re-authenticates/signs in with the same auth uid. I recieve the following error in the consoles of the other currently connected browsers:
Uncaught Error: Attempted to handle event
pushedData
on <myapp@model:user::ember938:anonymous:-JZ51lM7UkJUuD6pp9Yw> while in state root.deleted.uncommitted.
(note however, that the user/browser that did the signing out/re-logging in receives no error)
Is there anything else I need to do in this scenario to make sure that records automatically deleted by emberfire are fully committed in each connected client’s cached store, or is this a limitation of some sort?
For reference, here is how I am creating the records when a user signs in:
var user = this.store.createRecord('user', {
id: fbRef.getAuth().uid,
nickname: nickname,
joinedAt: new Date()
});
user.save();
And when they sign out:
this.store.find('user', fbRef.getAuth().uid).then(function(user) {
user.destroyRecord();
});
Issue Analytics
- State:
- Created 9 years ago
- Comments:11 (8 by maintainers)
Top GitHub Comments
I can confirm this, a record removed on the server will also remove locally, but the deleted record will still be cached locally in the store. This is because we use
model.deleteRecord
instead ofmodel.destroyRecord
here.On the client that deletes the record, as long as you use
destroyRecord
it is usually ok:But on a different client that observed the delete from the server, the deleted record is still there:
The workaround is to find the record and unload it manually before creating:
I’m inclined to say that using only
unloadRecord
is best: if a record has been edited locally before being deleted by another client, that is a legitimate data conflict that should raise an error to allow the client-side code to handle it gracefully (eg. alerting the user that the record has been deleted on the server, and asking if they want to re-create it using their local data, or just lose their changes)The one potential issue, as raised in #322, is that afaik just calling
unloadRecord
will not fire the record’sdidDelete
event. That being said, I’m not convinced thedidDelete
event should fire – there’s a clear difference between a record being deleted locally vs receiving an update from the server. But if the event is desired, then it could just be triggered manually.