From ef7f16a51c957a66e724b3c51d7e1e25632f41f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denilson=20S=C3=A1=20Maia?= Date: Fri, 13 Jun 2025 17:29:24 +0200 Subject: [PATCH] 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. --- packages/ui/components/overlays/src/OverlayMixin.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/ui/components/overlays/src/OverlayMixin.js b/packages/ui/components/overlays/src/OverlayMixin.js index 6b2bce481..ba906f75b 100644 --- a/packages/ui/components/overlays/src/OverlayMixin.js +++ b/packages/ui/components/overlays/src/OverlayMixin.js @@ -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;