Draft Restore

Draft Restore is a copy-paste React component that stops lost form after accidental refresh 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/draft-restore
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

StopsLost form after accidental refresh

Was this component page useful?

How do I install Draft Restore?

pnpm dlx shadcn@latest add @bollard/draft-restore

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

How do I use Draft Restore in React?

draft-restore-usage.tsx
import { DraftRestore, type FormValues, type StoredDraft } from "@/components/ui/draft-restore"

<DraftRestore
  key={opened}
  storageKey={KEY}
  values={values}
  serverValues={server}
  labels={labels}
  onRestore={setValues}
  defaultExpanded
/>

What input mistakes does Draft Restore catch?

  • Form work lost to a refresh, crash or closed tab
  • Stale draft values that would overwrite newer server values, kept server-side unless chosen
  • Old drafts, via an expiry (ttl)

What props does Draft Restore accept?

DraftRestore props
PropTypeDefault
storageKey* (required)

localStorage key, unique per record, e.g. `draft:invoice:1042`.

string—
values* (required)

The form's current values. Saved (debounced) whenever they differ from `serverValues`.

FormValues—
serverValues* (required)

The record as the server has it now.

FormValues—
onRestore* (required)

Receives the server values with your draft merged in. Conflicting fields keep the server value unless ticked.

(values: FormValues) => void—
onDiscard

Called after the draft is thrown away.

() => void—
labels

Readable field names for the preview.

Record<string, string>{}
exclude

Fields never written to storage (passwords, card numbers, one-time codes).

string[]NONE
delay

Debounce before saving, in ms.

number800
ttl

Drafts older than this (ms) are deleted instead of offered. Defaults to 7 days.

number7 * 86_400_000
message

Templates: `{when}` ("5 minutes ago") and `{count}` are filled in.

string"Restore your draft from {when}?"
conflictMessage

Message when the server changed fields since the draft.

string"Your draft from {when} clashes with {count} on the server."
expiresText

Text saying when the draft expires.

string"Expires in {days}"
previewLabel

Text for the preview toggle.

string"What differs"
restoreLabel

Restore button text.

string"Restore"
discardLabel

Discard button text.

string"Discard"
useMineLabel

Label for keeping the draft's value over the server's.

string"Use my draft"
conflictHint

Shown under a conflicting field.

string"Changed on the server after your draft. Kept unless you …
defaultExpanded

Show the field preview expanded from the start.

booleanfalse

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

How is Draft Restore accessible?

  • A role="region" labelled "Unsaved draft"
  • Message is aria-live="polite"
  • Preview toggle uses aria-expanded and aria-controls

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

What are the limitations and server boundaries?

  • Drafts live in this browser's localStorage: not on other devices, and cleared with site data
  • Don't store sensitive fields; use `exclude` for passwords, card numbers and similar
  • Anyone with access to the device can read localStorage

What expensive mistakes does Draft Restore stop?

Lost form after accidental refresh

Also known as

draft · autosave · localstorage · restore · form persistence · resume application · refresh lost data

What dependencies does Draft Restore require?

Draft Restore facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameDraft Restore
Registry identifier@bollard/draft-restore
Install commandnpx shadcn@latest add @bollard/draft-restore
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-11-15
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 Draft Restore

What form validation mistake does Draft Restore catch?

Draft Restore prevents lost form after accidental refresh. Autosaves a form locally and offers the draft back on reopen, keeping any value the server changed since, so work isn't lost or stale data restored. Catches: Form work lost to a refresh, crash or closed tab, Stale draft values that would overwrite newer server values, kept server-side unless chosen, Old drafts, via an expiry (ttl). Limitation: validate draft-restore schemas on backend.

How do I install draft-restore with shadcn?

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

What props customize Draft Restore?

Draft Restore accepts `storageKey`, `values`, `serverValues`, `onRestore`, `onDiscard`. Configures draft, autosave, localstorage behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of draft-restore?

Drafts live in this browser's localStorage: not on other devices, and cleared with site data. Don't store sensitive fields; use `exclude` for passwords, card numbers and similar. Anyone with access to the device can read localStorage Server requirement: backend verification for draft-restore.

How does Draft Restore meet accessibility guidelines?

A role="region" labelled "Unsaved draft". Message is aria-live="polite". Preview toggle uses aria-expanded and aria-controls. Minimizes errors: lost form data on refresh, restore draft.

Which components pair with Draft Restore?