Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic Storage unwanted changing

I'm having problems with the Ionic Storage.

When I log into my app, its saved on storage some configuration objects. On my last check was on IndexedDb.

But if I save any file changes or simply refresh the page, sometimes it switches from IndexedDb to Web SQL...

All my data is "lost" because the DB is a fresh new one.

Anyone knows why its happening or how to solve.

This is my app.module storage settings

IonicStorageModule.forRoot({
    name: '__cds',
    driverOrder: ['indexeddb', 'sqlite', 'websql']
})

I'm afraid the repercussions on this when I compiled into an App. So far I'm only on browser develop

That's how I set it

//response is an object I'm receiving from http call

this.storage.set('cds', response).then(() => {
    this.goHome();
});

That's how I get it

this.storage.get('cds').then(cds => {
    this.variable = JSON.parse(cds);
});

enter image description here

See, it's not "mantaining" the storage on a single db

like image 645
Rafael de Castro Avatar asked May 16 '18 11:05

Rafael de Castro


People also ask

Is ionic storage persistent?

2. Ionic native-storage — What and Why? This plugin is created because of the non-persistent property of LocalStorage in the WebView of Android and iOS. In iOS stored data from LocalStorage can be removed by the OS, when running out of memory.

How many types of storage are available in ionic framework?

Today we will explore the differences between Ionic Storage, Capacitor Storage, plain SQLite storage, and Ionic's Secure Storage solution.

How does ionic storage work?

Ionic Storage is our go to package for easily managing data. With Ionic Storage we can save JSON objects and key/value pairs to different storage engines, unified through one interface. Ok in easy this means, Storage will internally select which storage engine is available and select the best possible solution for us.

What is the limit of local storage in ionic?

Ionic Local Storage uses the local storage system of browser for key/value pairs storing. The limit of Local Storage is only 5MB.


1 Answers

Turns out the problem is a "feature" (I think) of Chrome Web Dev Tools. You see, when I refresh the app I was using the Toggle Device Toolbar

enter image description here

This helps the web design. If you notice this one is marked as Responsive

For a lot of other reasons, I suddenly changed my tab to one of Iphone size

enter image description here

I don't know why it works like this, but this little change make more than just alter the viewport size...

The storage base in use changed as well, and my problem begun.

In terms of a production App this will not be a problem, as I think the user was not able to "switch" viewport sizes on Chrome Dev Tools....

That's it. Thanks Marcol for your help!!

like image 177
Rafael de Castro Avatar answered Sep 28 '22 04:09

Rafael de Castro