-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
ngrx-data delete error #2553
Comments
Are there any news in regards to this issue. Will it be fixed soon? |
i have same issue here, any updates? |
ditto.. This only happens when I specifically use I have this signalR service getting notifications on data changes on push, it process the notification and update cache if required. When a child entity is being created together with its parent, I need to manually add the child to its cache so that all client get updated. I also find a very wired bug, if I subscribe to |
I went through the code base and found that in Therefore I would suggest use shareReplay({buffSize:1, refCount:true}) in places of shareReplay(1). @brandonroberts |
That sounds reasonable to me. If you could add a test to verify the fix that would be great |
Someone still want to put in a PR for this fix? |
Not sure how to write a test for this, haven’t learned the dark magic behind shareReplay yet. I manually put a finally operator in the pipe and I could see shareReplay does not get destroyed when all subscriptions were unsubscribed. Definitely need to be very careful using this operator. Always set refcount to true, unless it is intended to stay throughout the lifetime of the app. |
The thing is, if adding refcount to these shareReplay operators in the code base doesn’t break current tests, I would vote for it. |
I've encountered this same issue, as described by @rexebin. If I use addOneToCache after add, I get this: If I use upsertOneInCache after add, I get this: I've also noticed that if I use add then delete, it works. If I call add more than once consecutively (like in a file upload), then use delete, it crashes as shown above. |
Is anyone working on this? If not, mind if I take it? |
@AlmaniaM go for it |
There is a lot here...but I think for the original issue of delete errors after using addOneToCache or upsertOneInCache after an add a quick fix would be to add const trackedChange = chgState[id];
if (trackedChange) {
//removed for brevity
} else if (trackedChange.changeType === ChangeType.Updated) {
cloneChgStateOnce();
trackedChange.changeType = ChangeType.Deleted;
}... Should actually be: const trackedChange = chgState[id];
if (trackedChange) {
//removed for brevity
} else if (trackedChange.changeType === ChangeType.Updated) {
cloneChgStateOnce();
chgState[id].changeType = ChangeType.Deleted;
}... The second bug is in entity-collection-reducer-methods.ts the saveDeleteOne() method tries to mutate the action payload inside the reducer. ngrx/data's EntityAction extends ngrx/store's Action which I believe are immutable? From entity-action.ts: // Mutable actions are BAD.
// Unfortunately, these mutations are the only way to stop @ngrx/effects
// from processing these actions.
/**
* The action was determined (usually by a reducer) to be in error.
* Downstream effects should not process but rather treat it as an error.
*/
error?: Error;
/**
* Downstream effects should skip processing this action but should return
* an innocuous Observable<Action> of success.
*/
skip?: boolean; I'm not sure what to do with this, ngrx/data seems to require mutable actions. @rexebin adding The shareReplay issue seems like a completely separate issue but if its not getting destroyed it could be causing memory leaks. It is used most dispatcher methods that return and observable. |
@donohoea I can confirm that
I've used it everywhere I do a cache action. |
@RepentAndBelieveTheGospel glad that worked for you, just curious are you using Change Tracking? |
If anyone wants to make a PR for this go ahead. I've recently had something come up that's taking my attention away from this issue. I'll get back to this when I'm done and if no has fixed this yet. |
@donohoea Yes. |
I'd be willing to create the PR but would need a little advice on testing. After some more thought on the issue I believe both errors are the result of store runtime checks and aren't thrown in production. The "Cannot assign to read only property 'changeType' of object '[object Object]'" error is coming from the strictStateImmutability check and as shown in a previous comment I think a simple change would fix the issue. Just not sure how to write a test that captures the failing runtime check. As for the "TypeError: Cannot add property skip, object is not extensible," it's coming from the strictActionImmutability check. This could be solved by changing: function ignoreNgrxAction(action: Action) {
return action.type.startsWith('@ngrx');
} to: function ignoreNgrxAction(action: Action) {
return action.type.includes('@ngrx');
} I think this would capture ngrx/data actions in the exemption from strictActionImmutability as data actions are of the form: '[tag] @ngrx/data...' But again I'm unsure of how to capture the existing issue in a failing test. @timdeschryver maybe you have some thoughts as I believe you created the ignoreNgrxAtion function. |
Goods day.
I've been stuck here for a few days.And i really need some help.
I'm trying to use ngrx/data,it's working fine when add,update,get. but it gets error when delete.(not 100% happen)
Minimal reproduction of the bug/regression with instructions:
fontend:https://github.com/chobijaeyu/todoListAngular backend:https://github.com/chobijaeyu/todoListGin
service:
component.ts:
error:
or
Expected behavior:
what i expecte is delete item remote and local store.
actually it's did delete item remote,delete request return 200 even got this TypeError.
Versions of NgRx, Angular, Node, affected browser(s) and operating system(s):
donated $20,thanks for your brilliant works.
The text was updated successfully, but these errors were encountered: