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?

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.

Further reading

Problem with a question

System Design · Junior · question 36

Test yourself

Take the System Design · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz