On mobile, localStorage is erased after a few minutes of doing something else
Asked Answered
E

2

3

This problem only happens with my progressive React web app when I run it on my iPhone 5S (iOS 12.5.2) and LG Android phone. It does this with Mobile Chrome and Mobile Safari. Everything works fine on Chrome on my Macbook Pro.

I will have the app open then switch to something else on my phone. If I go right back to it within five or six minutes, the former state is not lost. But if I wait longer, the page reloads as if localStorage has been deleted. The longer I've been away, the longer it takes to restore the app. It had been doing that progressively extending reactivation delay part for a while, but only recently it started to also completely lose what's in localStorage too.

I looked at "Website Data" before and after this happens and saw that the site has about as much data before and after.

I have tried this both with and without using a service worker but I got the same results.

The site is: https://www.stopindoctrination.org

Exhalation answered 21/5, 2021 at 17:21 Comment(4)
If it also happens with your LG Android phone, then it's probably not ios or mobile-safari related. You might want to change the tags to react or javascript or pwa.Muco
If you manually kill the app and immediately return does the data also get wiped out?Carry
Good question, @CyberEd. If I kill the app and immediately return, the data is lost. I had not tried this on my desktop. I did it just now and it is working fine on the desktop. The problem only happens on my mobile device.Exhalation
It looks like this may be an ios bug in versions after 12.4.2 according to this thread, their test case is similar to yours: developer.apple.com/forums/thread/125627. Apple has said it will delete browser storage after 7 days so this might be a bug in their tracking prevention.Sleeve
F
1

apparently webkit deletes storage older than 7 days

Are you fetching and manually placing data into local storage or are you using the service worker to interupt fetch requests and cache the data?

If you're not already using the service worker I would suggest it.

Forint answered 22/6, 2021 at 16:10 Comment(2)
Question states they tried it both with and without the service worker.Sleeve
Thanks. I don't think that's it. The problem will happen after inactivity of a half an hour or so, not seven days. I'm not actually doing any fetches. The data are all bundled with the application code.Exhalation
S
1

Related to localStorage cleared on ios apps when device memory becomes low: https://github.com/scottjehl/Device-Bugs/issues/64

Thread states that IOS might clear localStorage data if the device memory is almost full, so that should be something to check, as it could be easily confirmed as a known bug or not.

Otherwise, this might be an ongoing bug with Apples tracking prevention acting up, which only intends to clear after 7 days.

Switching to a more reliable browser storage option like pouchdb which uses IndexedDB and WebSQL under the hood, rather than localStorage, might be a solution if the other concerns don't lead to a fix.

Sleeve answered 22/6, 2021 at 17:15 Comment(1)
Thanks. I don't think that's it because the problem happens on my Android device too and I can reproduce the problem by just closing the Safari app and re-opening it. This is a tricky one.Exhalation

© 2022 - 2024 — McMap. All rights reserved.