Performance: Form submission handling
MEDIUM IMPACT
This affects how quickly the page responds to user input and how fast the form data is processed and sent, impacting interaction responsiveness and perceived speed.
function MyForm() { const handleSubmit = async (e) => { e.preventDefault(); await new Promise(resolve => setTimeout(resolve, 0)); // yield to browser alert('Form submitted'); }; return ( <form onSubmit={handleSubmit}> <button type="submit">Submit</button> </form> ); }
function MyForm() { return ( <form onSubmit={(e) => { e.preventDefault(); // heavy synchronous processing for(let i=0; i<1000000000; i++) {} alert('Form submitted'); }}> <button type="submit">Submit</button> </form> ); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous heavy processing on submit | Minimal | 0 immediate, but blocks | High due to blocking | [X] Bad |
| Async lightweight submit handler | Minimal | 0 immediate | Low | [OK] Good |
| Default form submit with page reload | Full page reload | Many reflows | Very high | [X] Bad |
| Prevent default + async submit | Minimal | 0 immediate | Low | [OK] Good |