fix(overlays): don't call _setupOverlayCtrl() in OverlayMixin if the component is not connected

In our application, there is a very complicated logic that creates a bunch of form fields based on some data. It's very complicated, we hate that logic; but it exists, it works, and it is being used in production.

Somewhere in that logic, under a very specific case, a datepicker form field is created, connected, and then immediately disconnected. Don't ask me why, I said it is complicated.

This commit fixes a bug in OverlayMixin. The `connectedCallback` calls `_setupOverlayCtrl()` asynchronously, after a `Promise.then()`. Thus, by the time this setup function is called, the component has already been disconnected (and `disconnectedCallback()` has already been called).

The fix is simple: don't try to setup the overlay if the component is no longer connected.
This commit is contained in:
Denilson Sá Maia 2025-06-13 17:29:24 +02:00 committed by Thijs Louisse
parent 4460db7630
commit ef7f16a51c

View file

@ -179,6 +179,7 @@ export const OverlayMixinImplementation = superclass =>
super.connectedCallback();
this.updateComplete.then(() => {
if (!this.isConnected) return;
if (this.#hasSetup) return;
this._setupOverlayCtrl();
this.#hasSetup = true;