Safe Submit

Safe Submit is a copy-paste React component that stops helps prevent paying twice after a timeout before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/safe-submit
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsHelps prevent paying twice after a timeout

Was this component page useful?

How do I install Safe Submit?

pnpm dlx shadcn@latest add @bollard/safe-submit

The files land in your project. They're yours to edit.

How do I use Safe Submit in React?

safe-submit-usage.tsx
import { SafeSubmit } from "@/components/ui/safe-submit"

<SafeSubmit onSubmit={pay} pendingLabel="Paying…" successLabel="Paid">
  Pay ₹2,499
</SafeSubmit>

What input mistakes does Safe Submit catch?

  • Repeat clicks and Enter presses while a request is in flight (synchronous guard)
  • Double-taps right after a request settles (cooldown, default 400 ms)
  • Ambiguous failures (network, timeout, 408/429/5xx), retried with the same key
  • Definite failures, which mint a fresh key for the next attempt

What props does Safe Submit accept?

SafeSubmit props
PropTypeDefault
onSubmit* (required)

Does the work. Send `idempotencyKey` as an `Idempotency-Key` header. `formData` is the enclosing form's data.

(submission: { idempotencyKey: string; formData?: FormData }) => Promise<unknown>—
variant

Visual style of the button.

keyof typeof variants"default"
size

Size of the button.

keyof typeof sizes"default"
pendingLabel

Label while the request is in flight.

React.ReactNode"Submitting…"
successLabel

Label shown briefly after success.

React.ReactNode"Done"
retryLabel

Label after a failure.

React.ReactNode"Retry"
retrySafeHint

Shown after a retryable failure (network, timeout, 5xx).

React.ReactNode"Retrying is safe: it reuses the same request, so nothing…
retryUnsafeHint

Shown after a definite rejection (validation, 4xx).

React.ReactNode"Fix the issue, then try again."
errorMessage

Fallback when the error has no message.

string"Something went wrong"
resetAfter

Milliseconds the success label stays before the button resets.

number2000
cooldown

Ignore new attempts for this long after one settles, in ms.

number—
isRetryable

Decides whether a failure keeps the same key for a safe retry.

(error: unknown) => boolean—

* required. Also accepts the native props of <button> (className, aria-*, data-*…), passed through to it.

How is Safe Submit accessible?

  • Uses aria-busy instead of disabled while pending, so the button keeps focus
  • Pending, success and retry states have visible text labels; icons are aria-hidden
  • Errors render with role=alert and are linked via aria-describedby

Only what the source does. Test with your own screen reader and content before shipping.

What are the limitations and server boundaries?

This is a UX guard rail. Enforce on the server: Store the idempotency key with the result and return the stored result for repeats; add a unique constraint so duplicate writes fail.

  • Does not guarantee a single charge or record; that requires the server to honour the idempotency key
  • The key lives in memory: a reload, remount or second tab gets a new key
  • Classifies retryable errors with a default rule; pass isRetryable for your API

What expensive mistakes does Safe Submit stop?

Helps prevent paying twice after a timeout

Also known as

submit button · idempotency key · double submit · pay now · place order · loading button · debounce · razorpay

Field type

What dependencies does Safe Submit require?

Safe Submit facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameSafe Submit
Registry identifier@bollard/safe-submit
Install commandnpx shadcn@latest add @bollard/safe-submit
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about Safe Submit

How does Safe Submit prevent financial transaction errors?

Safe Submit prevents paying twice after a timeout. Blocks Repeat clicks and Enter presses while a request is in flight (synchronous guard), Double-taps right after a request settles (cooldown, default 400 ms), Ambiguous failures (network, timeout, 408/429/5xx), retried with the same key, Definite failures, which mint a fresh key for the next attempt before processing. Limitation: apply idempotency keys for safe-submit.

How do I install safe-submit with shadcn?

Run `npx shadcn@latest add @bollard/safe-submit`. Sources added: registry/default/safe-submit/safe-submit.tsx. Package requirements: lucide-react.

What props customize Safe Submit?

Safe Submit accepts `onSubmit`, `variant`, `size`, `pendingLabel`, `successLabel`. Configures submit button, idempotency key, double submit behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of safe-submit?

Does not guarantee a single charge or record; that requires the server to honour the idempotency key. The key lives in memory: a reload, remount or second tab gets a new key. Classifies retryable errors with a default rule; pass isRetryable for your API Server requirement: Store the idempotency key with the result and return the stored result for repeats; add a unique constraint so duplicate writes fail.

How does Safe Submit meet accessibility guidelines?

Uses aria-busy instead of disabled while pending, so the button keeps focus. Pending, success and retry states have visible text labels; icons are aria-hidden. Errors render with role=alert and are linked via aria-describedby. Minimizes errors: double charge on double click, duplicate order submitted.

Which components pair with Safe Submit?