-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Dialog triggers change detection on keyboard events #10143
Comments
You're using a very old Angular version which might have the dialog at a point where it was attaching its keyboard events to the |
Sorry, I'm actually using a newer version than the one used in StackBlitz. Angular CLI: 1.7.1 @angular/cdk: 5.2.2 |
I've tried using Chrome's debug tools to see what happens.
Phase 2
Phase 3
After another 5 dialogs opens and closes, the calls are like so:
|
The callback that causes the change detection is triggered by FromEventObservable, but I'm not sure who's calling it. |
Could it be that the dialog's keydownEvents observable is causing this? |
We have a global way of handling keyboard events for all overlays which is being used by the dialog. That being said, the global keyboard handler will be removed once there are no more open overlays. |
The "cdk-overlay-container" div remains even after the dialog is closed. Is that the overlay you're talking about? |
So what is an open overlay? does the cdk overlay container div is an open overlay? in my case, each dialog adds another event listener... 100 dialogs causes 100 event callbacks for every keydown on tge body element. |
Each dialog is an overlay, the overlay container isn't. I'll take a better look later to see if there's anything that could introduce the extra listeners. |
…tener Fixes the `OverlayKeyboardDispatcher` not removing the global event listener, even though the subscription gets removed correctly. The issue seems to come from the fact that rxjs attaches the event using `useCapture = true`, however it doesn't pass the `useCapture` parameter when unsubscribing, which leaves listener in place. These changes switch to using `addEventListener` and `removeEventListener` to manage the event. Fixes angular#10143.
Alright, I could confirm that the event listener wasn't being removed. I've submitted #10160 to address it. As for it running change detection, I think it should still do it while there's an open overlay, because the overlays need to be able to react to changes caused by key presses. |
I agree - change detection should be triggered while the dialog is open and receiving events - but the listeners should be removed when the dialog closes. Thank you Kristiyan! |
…tener (#10160) Fixes the `OverlayKeyboardDispatcher` not removing the global event listener, even though the subscription gets removed correctly. The issue seems to come from the fact that rxjs attaches the event using `useCapture = true`, however it doesn't pass the `useCapture` parameter when unsubscribing, which leaves listener in place. These changes switch to using `addEventListener` and `removeEventListener` to manage the event. Fixes #10143.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug, feature request, or proposal:
Opening a dialog using this.dialog.open(...) [where dialog is MatDialog from the constructor] causes my app to run a change detection for every key press - even after closing the dialog. After opening 10 dialogs, each key press triggers 10 change detections. The event triggers are only removed when I refresh the page and reload the app.
This happens even with a dialog that only has a mat-dialog-close button.
What is the expected behavior?
When a dialog is closed (no matter the reason), all listeners should be removed.
What is the current behavior?
The listeners remains, triggering a change detection event after every key press. Trying to hold down a key after a while causes hundreds of change detections every second, and low-end devices freeze.
What are the steps to reproduce?
I Couldn't reproduce it on StackBlitz. I'm using Angular v2.0.0.beta-12.
The text was updated successfully, but these errors were encountered: