fix(html-reporter): race condition where form submission used stale filterText state (#36260)

This commit is contained in:
Max Schmitt 2025-06-10 15:12:42 +02:00 committed by GitHub
parent 92994a8f85
commit 3cb987f383
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -60,13 +60,16 @@ export const GlobalFilterView: React.FC<{
event => {
event.preventDefault();
const url = new URL(window.location.href);
url.hash = filterText ? '?' + new URLSearchParams({ q: filterText }) : '';
// If <form/> onSubmit happens immediately after <input/> onChange, the filterText state is not updated yet.
// Using FormData here is a workaround to get the latest value.
const q = new FormData(event.target as HTMLFormElement).get('q') as string;
url.hash = q ? '?' + new URLSearchParams({ q }) : '';
navigate(url);
}
}>
{icons.search()}
{/* Use navigationId to reset defaultValue */}
<input spellCheck={false} className='form-control subnav-search-input input-contrast width-full' value={filterText} onChange={e => {
<input name='q' spellCheck={false} className='form-control subnav-search-input input-contrast width-full' value={filterText} onChange={e => {
setFilterText(e.target.value);
}}></input>
</form>