Performance: Form actions with server functions
MEDIUM IMPACT
This affects how quickly a form submission is processed and how fast the page updates after submission.
'use server' import { redirect } from 'next/navigation'; export const action = async (formData) => { // server-side processing return redirect('/success'); }; export default function MyForm() { return <form action={action}>...</form>; }
function MyForm() { const handleSubmit = async (event) => { event.preventDefault(); const data = new FormData(event.target); await fetch('/api/submit', { method: 'POST', body: data }); // client-side state update }; return <form onSubmit={handleSubmit}>...</form>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Client-side fetch on submit | Multiple (form + state updates) | Multiple reflows on state change | Medium paint cost | [X] Bad |
| Server function form action | Minimal (form submit only) | Single reflow after redirect | Low paint cost | [OK] Good |