SiteTidy
HomeGuidesReact Server Components (Part 6): Forms, Pending States and Optimistic UI
Frontend

React Server Components (Part 6): Forms, Pending States and Optimistic UI

Build mutation UX around React Server Actions: accessible forms, validation, pending states, optimistic updates, retries and progressive enhancement without lying to the user.

Published on August 15, 2026Updated August 31, 2026
React Server Components (Part 6): Forms, Pending States and Optimistic UI

The best Server Action is not the one with the fewest lines of code. It is the one whose user interface remains understandable while the network is slow, validation fails, another user changes the same record, or the server rejects the operation.

React’s form and action APIs can remove a lot of request plumbing. The difficult part remains the human part: what does the user see before, during and after the mutation?

Start with a real form

For form-shaped mutations, use the platform primitive:

export default function ProfileForm({ updateProfile }) {
  return (
    <form action={updateProfile}>
      <label htmlFor="displayName">Display name</label>
      <input id="displayName" name="displayName" required maxLength={80} />
      <button type="submit">Save profile</button>
    </form>
  )
}

This gives you semantics, keyboard behaviour, browser autofill and a submission model users and assistive technology already understand.

Do not replace a form with a pile of click handlers simply because the action eventually reaches server code.

Client validation is convenience, not authority

HTML constraints and client-side validation improve feedback:

<input name="displayName" required minlength="2" maxlength="80">

But the server must validate the same business rules independently.

A user can bypass browser validation. Requests can be constructed without your UI. Old clients can submit values your new frontend no longer produces.

The server owns truth.

Return field-level errors deliberately

A generic red banner saying “Something went wrong” is poor feedback when the actual problem is “that username is already taken.”

Return a safe structured result for expected validation failures:

type FormState = {
  ok: boolean
  message?: string
  errors?: Record<string, string>
}

Then associate the message with the relevant field in the UI.

Useful error feedback should:

  • explain what is wrong;
  • identify where it is wrong;
  • preserve the user’s safe input where possible;
  • explain how to fix it;
  • be exposed accessibly, not only through colour.

Pending state should acknowledge the action

When a user presses Save, silence is ambiguity.

A pending UI can disable the specific submit control and change its label:

'use client'

import { useFormStatus } from 'react-dom'

export function SubmitButton() {
  const { pending } = useFormStatus()

  return (
    <button type="submit" disabled={pending}>
      {pending ? 'Saving…' : 'Save changes'}
    </button>
  )
}

The pending state should be close to the action the user initiated. Freezing the entire page for a small profile change is rarely necessary.

Disabling is not idempotency

A disabled button reduces accidental duplicate clicks. It does not guarantee that only one mutation reaches the server.

Retries, multiple tabs and network behaviour can still produce duplicates.

If creating the same order twice would be harmful, solve that on the server with a domain constraint or idempotency mechanism.

UI state is not a consistency guarantee.

Optimistic UI works when rollback is cheap

Imagine a user stars a project. Waiting 500 ms before showing the star feels sluggish, so the UI can predict success immediately.

const [optimisticStarred, setOptimisticStarred] = useOptimistic(starred)

The mutation runs in the background and authoritative server state eventually reconciles the prediction.

This is a strong fit when:

  • success is common;
  • the action is easy to understand;
  • rollback is cheap;
  • a temporary prediction cannot cause serious harm.

Do not optimistically claim consequential success

“Payment complete”, “booking confirmed”, “account deleted” and “funds transferred” are not decorative UI states.

Do not present them as fact before the authoritative system confirms them.

You can still provide immediate feedback:

Processing payment…

is truthful.

Payment successful

before confirmation is not.

Optimistic UX should reduce latency, not manufacture certainty.

Keep the old value visible when useful

Not every pending state needs a skeleton.

If the user changes a filter and the previous results remain understandable, keeping those results visible while indicating an update is often less disruptive than replacing the entire panel with grey blocks.

Pending UI should preserve context where possible.

Multiple actions in one form

Forms can have more than one action. A draft editor might expose Save Draft and Publish.

Those operations have different consequences and may require different authorization.

Do not infer the requested operation from a mutable hidden field and then route everything through one enormous function if separate server operations would be clearer.

Each consequential action should have an explicit server-side authorization path.

Validation races

A username may be available when client validation checks it and unavailable by the time the server commits the change.

An item may be in stock when the page renders and sold out when the order arrives.

Client validation can improve responsiveness, but uniqueness, inventory, balances and other shared constraints must be enforced atomically at the authoritative data layer.

Expect the final server mutation to reject assumptions that were true a moment earlier.

Preserve accessibility during updates

Dynamic mutation UI can become noisy for screen-reader users if every state change is announced indiscriminately.

Use status messaging intentionally:

<p role="status" aria-live="polite">
  {message}
</p>

Use assertive announcements sparingly. Move focus only when doing so genuinely helps the user recover — for example focusing a form-level error summary after a failed submission.

Do not remove keyboard focus by replacing the entire form tree unnecessarily.

Redirect after create when the new resource has a destination

After creating /projects/123, redirecting to the new project’s canonical page can be cleaner than leaving the user on a stale creation form.

The mutation lifecycle becomes:

  1. validate;
  2. authorize;
  3. create;
  4. invalidate relevant listings;
  5. redirect to the canonical resource.

This also avoids accidental refresh/resubmission patterns in architectures that support the flow.

Keep action results small

A Server Action response is not an invitation to return your entire updated database graph.

Often the UI needs only:

return {
  ok: true,
  message: 'Profile updated.'
}

If the framework re-renders/revalidates authoritative server content after the mutation, returning a duplicate 50 KB object may simply increase serialization and complexity.

File uploads need special thought

Forms make file input easy, but production upload architecture still matters.

Consider:

  • maximum body sizes;
  • host/serverless execution limits;
  • MIME/type validation;
  • content scanning where appropriate;
  • storage permissions;
  • direct-to-object-storage upload flows for large files;
  • progress UI;
  • abandoned uploads;
  • filename sanitisation and generated storage keys.

A Server Action may be perfectly reasonable for a small avatar and completely wrong for a multi-gigabyte video.

Long-running work should leave the request

If a form triggers a ten-minute report generation job, keeping the action request open for ten minutes is usually poor architecture.

The action can validate and enqueue durable work, then return a job identifier or redirect to a status page.

Background processing, retries and progress belong to infrastructure designed for them.

Error recovery should match the failure

Not all failures deserve the same button.

  • Validation error: fix the highlighted field.
  • Conflict: reload authoritative data and explain what changed.
  • Temporary dependency failure: allow retry.
  • Authentication expiry: restore authentication flow safely.
  • Permission failure: do not keep offering a Retry button that can never succeed.

Good mutation UX tells the user what they can do next.

Fast UI still needs a fast page

Use SiteTidy to inspect the production performance and page-level issues around your interactive React experience.

Run Free Audit →

Mutation UX checklist

For each form or action, verify:

  • the operation works with semantic controls;
  • browser validation improves feedback but server validation remains authoritative;
  • pending state is visible near the initiated action;
  • duplicate submission is safe at the server where necessary;
  • expected validation errors are field-specific and recoverable;
  • optimistic updates are only used when prediction is safe;
  • consequential success is not announced prematurely;
  • shared constraints are enforced atomically;
  • focus and status announcements remain accessible;
  • large uploads use an architecture appropriate to their size;
  • long-running work moves to durable background processing;
  • successful writes revalidate or redirect to authoritative state.

The principle to keep

Server Actions can make forms beautifully simple, but simplicity in the source code is not the goal.

The goal is an interaction that remains truthful, recoverable and understandable under real network and server conditions.

Make the happy path fast. Design the unhappy paths just as carefully.

Ready to audit your site?

Put this guide into practice immediately using our free tools.

Browse 180+ Free Tools