fix(form-core): don't remove event listeners if _focusableNode was not set

This fix is similar to the previous commit.

Under very specific circumstances on a very complicated application logic, a file input field (that
extends from FocusMixin) gets created and immediately destroyed. This unfortunately causes an
error, because the `disconnectedCallback()` gets called to remove the event listeners for a
component that hasn't been fully set up.

> Uncaught TypeError: this._focusableNode is null
This commit is contained in:
Denilson Sá Maia 2025-06-13 18:10:45 +02:00 committed by Thijs Louisse
parent ef7f16a51c
commit 1d3a00c022

View file

@ -198,6 +198,7 @@ const FocusMixinImplementation = superclass =>
* @private * @private
*/ */
__teardownEventsForFocusMixin() { __teardownEventsForFocusMixin() {
if (!this._focusableNode) return;
this._focusableNode?.removeEventListener( this._focusableNode?.removeEventListener(
'focus', 'focus',
/** @type {EventListenerOrEventListenerObject} */ (this.__redispatchFocus), /** @type {EventListenerOrEventListenerObject} */ (this.__redispatchFocus),