Guard against lost work
Warn before unsaved work is lost; confirm or allow undo on deletes.
Web Interface Guidelinesvercel-labs · command.md · Forms
Warn before navigation with unsaved changes (`beforeunload` or router guard)
Web Interface Guidelinesvercel-labs · command.md · Navigation & State
Destructive actions need confirmation modal or undo window—never immediate
From web-design-guidelines (Web Interface Guidelines).
Edit, then leave
Edit both notes, then press Notes to go back.
No guardBad
navigate("/notes")0 chars lostRouter guardGood
if (dirty) confirmLeave()0 chars lostrouter.beforeEach(async () => {
if (!note.dirty) return true;
const choice = await confirmLeave();
if (choice === "save") await note.save();
return choice !== "keep";
});
Delete a row
Delete files in each list, then try to undo.
ImmediateBad
No files.
api.delete(id)0 lostUndo windowGood
No files.
toast({ action: "Undo" })0 lostConfirm or undo?
Delete the project in both panes, then recover it.
Confirmation modalAsk first
role="alertdialog"0 clicksUndo windowAct, then offer
softDelete(id)0 clicksWhy it matters, pros and cons
Why it matters
Back, reload and delete each erase work in one click. A guard makes it free.
Pros
- A mis-click stops being data loss.
- Undo keeps intended deletes at one click.
- Rare prompts get read, not dismissed.
Cons
- Prompting on a clean form trains click-through.
beforeunloadshows generic text and cannot offer Save.- Undo needs deferred or soft deletes server-side.