System Design · Junior · Question 36 of 75
How do you avoid losing a draft of a long form if the tab is closed by accident?
- ✓Correct answer: Periodically save the draft to
localStorageor to the server - 2Forbid the user from closing the tab until the form is submitted
- 3Keep the draft in a JavaScript variable in memory
Explanation
Autosave (with debounce) to localStorage/IndexedDB or the server restores the data when the user returns. You can additionally warn via beforeunload, but you can't and shouldn't forbid closing. An in-memory variable disappears with the tab.