As connectedCallback is called after closing the dialog, any attempts to e.g. register global listeners in connectedCallback and removing them in disconnectedCallback will fail and the listeners will remain after the dialog is closed.
The reason for the extra events is that the <entity-editor> element is first created inside <vaadin-dialog><vaadin-dialog-overlay> and then <vaadin-dialog-overlay> is moved to the <body> element. After closing the dialog, the <vaadin-dialog-overlay> element is moved back inside <vaadin-dialog>.
It seems like the correct solution would be that <vaadin-dialog-overlay> is never attached to <vaadin-dialog> in the first place, nor moved back there.
Workaround:
connectedCallback() {
super.connectedCallback();
if (this.parentElement?.parentElement == document.body) {
// This is a real connect
this.connected = true;
document.body.addEventListener(...)
}
}
disconnectedCallback() {
super.disconnectedCallback();
if (this.connected) {
// This is a real disconnect
this.connected = false;
document.body.removeEventListener(...)
}
}
Given
and
You will see the following in the log when opening the dialog
and the following when closing it
As
connectedCallback
is called after closing the dialog, any attempts to e.g. register global listeners inconnectedCallback
and removing them indisconnectedCallback
will fail and the listeners will remain after the dialog is closed.The reason for the extra events is that the
<entity-editor>
element is first created inside<vaadin-dialog><vaadin-dialog-overlay>
and then<vaadin-dialog-overlay>
is moved to the<body>
element. After closing the dialog, the<vaadin-dialog-overlay>
element is moved back inside<vaadin-dialog>
.It seems like the correct solution would be that
<vaadin-dialog-overlay>
is never attached to<vaadin-dialog>
in the first place, nor moved back there.Workaround: