facebook / Rapid

The OpenStreetMap editor driven by open data, AI, and supercharged features
https://rapideditor.org
ISC License
515 stars 91 forks source link

'unload' event is deprecated #1508

Open bhousel opened 2 months ago

bhousel commented 2 months ago

We use this event to release the localStorage mutex, but it seems like browsers are dropping support for it.

https://github.com/facebook/Rapid/blob/695d7f2fa93aaea4b98a2139157922956699fd8b/modules/core/EditSystem.js#L145

more info here https://developer.mozilla.org/en-US/docs/Web/API/Window/unload_event https://chromestatus.com/feature/5579556305502208

eneerhut commented 2 weeks ago

Is the purpose of this event to help us understand when someone leaves the site @bhousel?

bhousel commented 2 weeks ago

Is the purpose of this event to help us understand when someone leaves the site @bhousel?

Yes - the "mutex" mentioned above is a trick that means that if you have multiple Rapid tabs open then only one of them will be allowed to backup the user's edits. When you close the tab, it releases that lock.

The whole thing is kind of messy and we should probably rethink how saving user's backups should work.

eneerhut commented 2 weeks ago

Thanks for clarifying. Sounds like pretty core functionality to avoid failure states and edit conflicts.