Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage cleared everytime the app closes/on refresh #165

Open
YogliB opened this issue Feb 24, 2019 · 16 comments
Open

Storage cleared everytime the app closes/on refresh #165

YogliB opened this issue Feb 24, 2019 · 16 comments

Comments

@YogliB
Copy link

YogliB commented Feb 24, 2019

I'm using @ionic/storage v2.2.0 with Ionic v4 and Angular v7, and in development mode, the storage (IndexedDB in that case) is cleared on refreshing the page.

On mobile (with Cordova on Android v7.1.4), the storage is cleared upon closing the app.

I use NO extra settings in my app for the storage and used it just like the instructions here (I installed the npm package and the Cordova plugin).

@jcbriones
Copy link

I actually have the same problem! I notice that the cordova-sqlite-storage has an option to set androidLockWorkaround: 1 in the config setting. I tried setting that in the config like this

IonicStorageModule.forRoot({
      androidLockWorkaround: 1,
}),

but it was giving me an error saying StorageConfig does not have androidLockWorkaround

Can anyone please verify. Thank you.

@YogliB
Copy link
Author

YogliB commented Mar 20, 2019

@jcbriones
From the source code (The object inside of the forRoot method):

export interface StorageConfig {
  name?: string;
  version?: number;
  size?: number;
  storeName?: string;
  description?: string;
  driverOrder?: string[];
  dbKey?: string;
}

@Taylorsuk
Copy link

Hi @YogliB @jcbriones, I've got the same issue. I don't recall this being the case with the previous v2.1.1.

Have you managed to find a fix?

@YogliB
Copy link
Author

YogliB commented Aug 29, 2019

@Taylorsuk Nope, just stopped using it...

@codewithtushar
Copy link

@YogliB I am facing the same issue what alternative have you used if not using this ?

@moconnell9
Copy link

I am also facing this issue.

@YogliB
Copy link
Author

YogliB commented Dec 8, 2020

@YogliB I am facing the same issue what alternative have you used if not using this ?

We've moved on to developing PWAs, so now I just use LocalForage.

@dgatto
Copy link

dgatto commented Jan 13, 2021

I'm having this issue as well, anyone find anything new?

@Hanzofm
Copy link

Hanzofm commented Jan 25, 2021

Same problem here.

On 'device platforms' (ios/android) works fine but on 'browser' platform the storage is clear every app startup or reload. However without reload or restart works fine.

this is my env:

  IonicStorageModule.forRoot({
            name: 'MyAppDB',
            driverOrder: ['sqlite', 'localstorage', 'indexeddb', 'websql'],
        }),
Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
"@ionic/storage": "2.3.1",
"cordova-browser": "^6.0.0",
"cordova-sqlite-storage": "^5.1.0",

compiled with
ionic cordova build browser --prod

And upload www folder to AWS

Some solution or workaround? Someone managed with this?

@mlynch
Copy link
Contributor

mlynch commented Mar 9, 2021

Not sure why this would happen, perhaps a browser config issue? About to release v3 in a few weeks so hopefully it addresses this.

@argvil19
Copy link

argvil19 commented Aug 25, 2021

Still happening on 3.0.4 / Ionic 5.4.16

UPDATE: Found out that this happens when available space is low. Browser gets rid of temporary storage when lacking space. https://developer.chrome.com/docs/apps/offline_storage/#table

@aaronbach
Copy link

@argvil19 do you have some kind of workaround? I encounter this problem with @ionic/storage@3.0.6. We are using Ionic Appflow Live Updates. This Bug causes the App to logout on old android devices. If you shutdown the App and reopen it afterwards, you are logged in again, because the storage is loaded correctly.

At the moment I#'m experimenting with saving the data from the storage in a file and reload this file, if the storage is empty.

We are Using the following Drivers:

IonicStorageModule.forRoot({
  driverOrder: [Drivers.IndexedDB, Drivers.LocalStorage]
}),

@elreco
Copy link

elreco commented Apr 11, 2022

@aaronbach we have the same problem :( did you find a workaround?

@aaronbach
Copy link

@elreco yes and no. We have implemented a step before every Appflow Update, which persists the whole ionic storage to a json file and tries to reloads it everytime you are on the login route.

the workaround caused additional troubles, so we decided to switch off AppFlow Updates on Android.
The main reason for this was, that some AppFlow updates ran very long on older Android devices.

@elreco
Copy link

elreco commented Apr 11, 2022

@aaronbach thank you so much for your answer! You are right, and appflow updates are very fast on iOS.

Do you think that it can works better if we use a sqlite plugin without the ionic storage package?

Like using this: https://ionicframework.com/docs/native/sqlite and make manual sql queries to save our persistent data?

@aaronbach
Copy link

@elreco when you only need storage in a mobile app, it should be worth trying:
See https://ionicframework.com/blog/choosing-a-data-storage-solution-ionic-storage-capacitor-storage-sqlite-or-ionic-secure-storage > SqlLite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests