Unreliable localStorage leads to unhappy users

I have a report of a disappointed user because of localStorage. Specifically, it is about the game Wonster. It uses the localStorage to store the day streak. And now its gone. Here we can see that localStorage will not be deleted when it is not used in a while because a 30 days streak was deleted. So a 30-daily use lead to deletion.

localStorage is used to store local data in order to not pollute the common webxdc event database. It would be great for a WebXDC developer to have such a local storage which is reliable.

Maybe localStorage.getItem()/.setItem() could be hijacked by the WebXDC sandbox to lead to reliable stored data.

1 Like

Is this about Android, iOS or Desktop?

It was Android

1 Like

@r10s @adbenitez sounds like it’s worth an issue?

I think it should be filed as a bug in Wonster. Local storage is not supposed to be reliable, it can be cleared randomly at any time and is not synchronized between devices, it can only be used for caching.

2 Likes

As a WebXDC developer, what should I use instead if I want to store local things that do not have to be synchronized? (in order to not pollute the synchronized group event database)
So what should the Wonster code be changed to in order to realize this idea of storage saving?

Use sendUpdate. To cleanup database we may introduce some API later to squash updates locally (e.g. replace local updates with IDs 1…N with a single update so you don’t have to re-read them on the next app start) but for now I suggest not to worry about the database state and just store the score of each game in an update. Even if someone plays every day for an year in a group, you will maybe get a few thousands updates, it’s not much.

Also speaking of the game streak, it has to be synchronized at least between multiple devices of a single user.

It already sends an update each time someone plays a game, you can calculate your streak from the updates without changing what is sent. Maybe have to add selfAddr if it is not there yet to recognize your updates, but the number of updates sent will not change.

3 Likes

Indeed, if you have multiple devices, you can start to guess the same word of the day again with all tries reset.

Fixing it would lead to ~ 5.475 additional permanent updates per year (instead of 1.825).

  • lets say 4 tries per day (instead of 1 win or lose event)
  • lets say 5 group members
  • 365 days

Probably still OK.

This would be great. I’ve thought about exporting and importing data into a new app to reach this. But something like sentUpdate({payload: …, deleteEvents: 1-10, 13, 14-20}) would be great. :star_struck:

With deletion it could be 1 event per user ever. This would be a huge difference :grinning:

yep this need to be fixed in Wonster, also to properly sync the stats across devices, we already send a status update when user plays it is just not having any useful logic information to sync data

1 Like

This sounds wrong to me.

  • When porting existing web apps, it’s not easy to migrate everything to webxdc.sendMessage() right away.
  • There are cases where, in an app context, you don’t want to make all the state public. For example, we have the CryptoWhisper app in the store, and IMU it relies in storing the private key in local storage. Losing the key would mean losing access to messages.
  • Some apps might want to store something like per-user app-specific preferences / settings.

This either needs to get fixed, or at the very least outlined strongly in the docs.

1 Like

Yes, I totally agree.
It’s normal that any kind of applications need a reliable way to store local data. And sending a message over internet only to keep some local data seems a high price to pay.

localStorage API on itself is limited and offers no warranties to web developers, the one in the web browsers used by DC is not special

IIRC DC desktop has an option to clear localStorage which should be removed IMHO to avoid accidents, in android if user clears app cache this might delete localStorage etc

There is this section in the docs:
https://webxdc.org/docs/faq/storage.html

But exact words could be adjusted to say that the data will be lost eventually and you should be prepared that it may happen at any time.

1 Like

In browsers pages can request persistent storage and I think for installed PWAs there is also different limitations.

Although I think it’s probably easier to create a new webxdc API to store local data than trying to hijack the browsers APIs in all plataforms.

And now that there is Realtime channels this is even more necessary, imagine that you receive some important data over a Realtime channel, the only reliable way to keep the data is to send it as a webxdc update after you already received it through RTC, how absurd does that sounds ??

1 Like

Also in browsers it’s usually not necessary a way to store reliable local data because the server can do that and the web page can request the data to the server when it needs it, but webxdc do not have servers so they do need a reliable way to store local data.

1 Like

yeah and for that webxdc needs to provide some API, localStorage is a browser API with temporary cache in mind, not for reliable permanent storage