Warning: THIS WAS VIBE TROUBLESHOT BUT THE LLM SAYS IT IS, AND I QUOTE, "VERY CONFIDENT"
Context from Kibana issue....apologies to those not in Elastic for not being able to see this
EuiValidatableControl uses useEffect to call setCustomValidity('Invalid') on the underlying DOM element when isInvalid changes. Because useEffect runs after paint, there is a one-frame window where the DOM element's validity is stale relative to React state. If a form submit (via type="submit" button) fires during this window, the browser's native constraint validation sees the stale customValidity and shows a native "Invalid" tooltip—even though React has already cleared isInvalid.
Relevant code (validatable_control.js):
useEffect(function () {
if (controlEl == null || typeof controlEl.setCustomValidity !== 'function') return;
if (isInvalid) {
controlEl.setCustomValidity('Invalid');
} else {
controlEl.setCustomValidity('');
}
}, [isInvalid, controlEl]);
Suggested fix: Replace useEffect with useLayoutEffect, which runs synchronously before paint:
useLayoutEffect(function () {
if (controlEl == null || typeof controlEl.setCustomValidity !== 'function') return;
if (isInvalid) {
controlEl.setCustomValidity('Invalid');
} else {
controlEl.setCustomValidity('');
}
}, [isInvalid, controlEl]);
This closes the timing gap between React state and DOM validity state, preventing stale native validation tooltips.
Affects: Any EUI form control (EuiFieldText, EuiTextArea, etc.) inside a <form> without noValidate that toggles isInvalid during user interaction.
Warning: THIS WAS VIBE TROUBLESHOT BUT THE LLM SAYS IT IS, AND I QUOTE, "VERY CONFIDENT"
Context from Kibana issue....apologies to those not in Elastic for not being able to see this
EuiValidatableControlusesuseEffectto callsetCustomValidity('Invalid')on the underlying DOM element whenisInvalidchanges. BecauseuseEffectruns after paint, there is a one-frame window where the DOM element's validity is stale relative to React state. If a form submit (viatype="submit"button) fires during this window, the browser's native constraint validation sees the stalecustomValidityand shows a native "Invalid" tooltip—even though React has already clearedisInvalid.Relevant code (
validatable_control.js):Suggested fix: Replace
useEffectwithuseLayoutEffect, which runs synchronously before paint:This closes the timing gap between React state and DOM validity state, preventing stale native validation tooltips.
Affects: Any EUI form control (
EuiFieldText,EuiTextArea, etc.) inside a<form>withoutnoValidatethat togglesisInvalidduring user interaction.