Async pipe not triggering change detection unless debounce is used
Minimal reproduction of the bug/regression with instructions:
Started from a working sample app for simplicity. I modified it to reproduce the issue. https://github.com/jbenezech/angular-ngrx/tree/ngrx_async_issue
A component emits an event, the container dispatches the action. The reducer changes a boolean in the state to true The effect dispatch a success action The reducer changes the boolean in the state back to false
The change is not detected and the component's ngOnChanges function is never called.
If using debounce on the effect, the change is properly detected https://github.com/jbenezech/angular-ngrx/blob/e99f6edc054eaf53263d3d494b27f083ce944a02/src/app/store/effects/user.effects.ts#L36
Expected behavior:
State change is not happening outside of angular and should be detected.
Versions of NgRx, Angular, Node, affected browser(s) and operating system(s):
Angular 7, NgRx 6.1.0, Node 8.12, Chrome latest, Ubuntu 16.04
Other information:
Hey jb, I think the issue here is that ngOnChanges only gets called after change detection notices a change, and your effect changes the value back before change detection runs. When you have a debounce on the effect, Angular change detection has time to run before the boolean is changed back.
Hi. Thanks for your reply. I get what you're saying but does that mean I
need to purposely slow down my app, and add debounce, timeout... everywhere
so that angular has time to "do his stuff" ?
I'm new to Angular but it sounds like a broken design
If it's angular by design and not NgRx specific, let me know, I'll move the issue over
On Wed, 17 Apr 2019, 18:23 Ryan Sandberg, [email protected] wrote:
Hey jb, I think the issue here is that ngOnChanges only gets called after change detection notices a change, and your effect changes the value back before change detection runs. When you have a debounce on the effect, Angular change detection has time to run before the boolean is changed back.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ngrx/platform/issues/1759#issuecomment-484043390, or mute the thread https://github.com/notifications/unsubscribe-auth/AHl8wMdKPIQf-ARnmfPQSZtx6UdPHAqyks5vhwQzgaJpZM4c0qK- .
You're correct, adding debounce everywhere isn't the right way to go about this. My first thought is that you probably don't need to dispatch a success action. Most examples that dispatch success actions do so in response to something that passes or fails after some amount of time passes, like an API call. If you remove that effect, you should see your ngOnChanges get called.