Page MenuHomePhabricator

Consider switching from sessionStorage to localStorage for autosave
Open, Needs TriagePublic

Description

We used sessionStorage because we wanted to ensure the autosaved changes won't pile up forever, and a guarantee that it will be deleted when the "session" ends was very convenient (saves us code for cleaning up expired entries, and defining when they even should expire, etc.).

But it seems that sessionStorage data is deleted in several cases where autosave would be very convenient:

  • Mobile browsers unloading the page (T217783)
  • Machine shutting down unexpectedly, e.g. due to power loss (T214543)
  • (Unclear what happens in case of a single browser tab crashing vs entire browser crashing, might behave differently)

We should therefore consider switching from sessionStorage to localStorage.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

The main issue with localStorage is not just that we would need to manage old entries, but that we could also run into limits more often (which would probably result in data loss)

  • Even with aggressive garbage collection some users may end up with 10s or 100s of documents in storage at any one time
  • ResourceLoader uses up a lot of the storage for its cache
  • On Firefox quota is shared across the whole domain, not subdomains, making it more likely to hit quota. RL caching was disabled on FF for this reason.

Mobile browsers unloading the page (T217783)

It's unclear from that bug if this is a general problem with iOS, or a rare edge case where they loaded a webview inside GChat.

If you re-open the same tab (ctrl+shift+t) it should keep your edit.

It actually doesn't keep it. But that's probably acceptable.

(If we wanted to change that, then I think it would require doing T218663 first)

Notes from conversation with @Esanders:

  • This would allow people to write a comment draft, close the browser tab, open a new browser tab with that same talk page and notice their in-progress comment is how they left it.
    • Note: this would not allow people "carry" drafted comments across devices or browsers.

Some users have reported that sessionStorage does not appear to persist in Firefox when the browser crashes.

Firefox also has terrible support for localStorage (https://bugzilla.mozilla.org/show_bug.cgi?id=1064466).