{"success":true,"name":"warn-before-discarding-unsaved-work-guard-navigation-closing","description":"A user with a half-filled form can leave or go back and lose everything silently","category":"ai-brimind","path":"ai-brimind/warn-before-discarding-unsaved-work-guard-navigation-closing/SKILL.md","file":"SKILL.md","content":"---\nname: warn-before-discarding-unsaved-work-guard-navigation-closing\ndescription: \"A user with a half-filled form can leave or go back and lose everything silently\"\n---\n\n# Warn Before Discarding Unsaved Work: Guard Navigation, Closing, and Back\n\n## When to use\nA screen accumulates unsaved input (forms, editors, settings), and navigating away, pressing back, or closing the tab discards it without warning.\n\n## Example request\nten minutes of typing, an accidental back press → gone, no question asked; silent discard. tab closed with edits pending → the browser's leave-warning was never wired; unguarded exit. in-app navigation away from a dirty form → client routing bypasses browser warnings entirely; unguarded route change. — each let one stray click erase real work.\n\n## Instructions\nAct as a doorman who stops anyone leaving with wet paint on the canvas: 'you have unsaved work — leave anyway?' First, track dirtiness honestly: the screen knows whether current input differs from the last saved state — set on change, cleared on save or discard — because guarding requires knowing there is something to guard, and warning on pristine forms trains users to ignore the warning. Then guard every exit, and know they are separate doors: closing the tab or hard-navigating needs the browser's before-unload mechanism (registered only while dirty — its mere presence disables tab-sleeping optimizations — and showing only the browser's generic prompt; custom text there is ignored); in-app route changes bypass that entirely and need the router's own navigation guard, where you CAN show a proper dialog with real choices — stay, discard, or save-and-go. Cover the platform's back semantics too: on TV and mobile, the back button is the most-pressed key in the room. Consider the stronger cure alongside the warning: periodic draft auto-save turns catastrophic loss into a 'restore draft?' offer, and for long forms it beats any dialog. Test each door with a dirty form: tab close, refresh, in-app link, back press. Only ship when no path exists by which one accidental input destroys many minutes of a user's typing without a question asked.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #792\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}