I've removed the beforeunload event. Instead, on unload, the current map gets saved to localStorage.
I think it would be better to save state as the user creates it (every time something is pushed onto the "undo" stack). That way, state will survive even if the browser tab crashes.
(If we do this, I think it would make sense to switch to IndexedDB, which has an async API, to ensure that saving the map doesn't lock the main thread. I recommend idb-keyval.)
Apropos this comment:
I think it would be better to save state as the user creates it (every time something is pushed onto the "undo" stack). That way, state will survive even if the browser tab crashes.
(If we do this, I think it would make sense to switch to IndexedDB, which has an async API, to ensure that saving the map doesn't lock the main thread. I recommend idb-keyval.)