AddThisFeature

Async Button

Make every button that talks to the network behave the same way while it waits.

moderate Components & Primitives

What it adds

A pending behaviour for buttons that trigger requests, covering submission locking, result feedback, and cancellation.

What your agent is told to do

5
  1. 1

    Find every control that fires a request, a job, or an export, and give it a pending state that begins on activation rather than when the response is nearly back.

  2. 2

    Lock the button against a second activation for the whole life of the request, including double clicks, the enter key held down, and a repeat tap on a laggy mobile connection.

  3. 3

    Define what happens on each outcome: success, a handled error, a network failure, and a request that outlives a sensible timeout. Silence on any of those reads as a broken button.

  4. 4

    The visual hierarchy, sizing, and hit area of these buttons belong to Button System; this brief owns only what happens between activation and resolution. Do not redefine the button's appearance here.

  5. 5

    Do not disable the surrounding form while one button is pending. Locking unrelated fields and the cancel control traps the user inside a request they can no longer escape.

Edge cases it handles

7
  • Two activations must produce one request. Guard on the in-flight request itself rather than on a visual disabled attribute, which arrives a frame late and can be bypassed by the keyboard.
  • Swapping the label for the word Loading destroys the button's accessible name, so a screen reader user who tabs back to it no longer knows what it does. Keep the original label and announce the busy state separately.
  • Success, error, timeout, and cancellation are four distinct endings and each needs its own resolution. A button that simply returns to idle after a failure tells the user the work succeeded.
  • Disabling unrelated controls while a request is in flight blocks the user from correcting the very field that caused the error.
  • A response that arrives after the user has navigated away must not update a button that no longer exists or resurrect a stale error.
  • Work expected to take longer than a few seconds needs progress or a cancel affordance rather than an indefinite spinner.
  • A request that fails instantly must still show the pending state long enough to be perceived, or the button appears not to have reacted at all.

Definition of done

8
  • Every network-triggered button enters a pending state on activation.
  • Repeated activation during a pending request produces exactly one request.
  • The button's accessible name is unchanged while pending, with the busy state conveyed separately.
  • Success, error, timeout, and cancellation each resolve to a distinct, visible outcome.
  • Controls unrelated to the pending action remain usable throughout.
  • A response arriving after the view has been left causes no error and no stray state update.
  • The feature matches the existing design system.
  • No existing functionality is broken.

Related features

How it works

  1. 1

    Copy the link

    Grab the Markdown instruction URL for this feature.

  2. 2

    Give it to your AI

    Paste it into Claude Code, Cursor, v0, Lovable — whatever you build with.

  3. 3

    It inspects, then implements

    Your agent reads your existing app first, then adds the feature to fit it.

Works with your stack

These instructions are written to adapt. They tell the agent to detect your framework, match your existing design system, and reuse what you already have — rather than assuming a particular stack.

Need it tighter than that? Customize the feature and tell it exactly what you're running.