Comments (2)
In most browsers the best you can do is request the browser not evict data for the site. Some browsers prompt the user for allowing this. The MDN docs for "Storage quotas and eviction criteria" is helpful.
It's important to note that Chrome will default to refusing to allow setting data to persist if there is not sufficient user interaction to tip the scales so the request should not be ran on page load or similar. Good news is that despite this it looks like data is rarely evicted even without persist set. You can read more from Chrome devs here.
It could be handy to have a method in this library to handle this but there are limitations since it's not guaranteed to be accepted and care should be taken on when it would be called. Additionally, the persist option extends beyond IndexedDB to other things like cookies, cache, local storage, and more. If this gets added I'd recommend noting the limitations and best practices mentioned above in the documentation. Otherwise the following should be helpful.
Example to check if data is set to persist (source):
if (navigator.storage && navigator.storage.persist) {
navigator.storage.persisted().then((persistent) => {
if (persistent) {
console.log("Storage will not be cleared except by explicit user action");
} else {
console.log("Storage may be cleared by the UA under storage pressure.");
}
});
}
Example to request the browser set data to persist (source):
if (navigator.storage && navigator.storage.persist) {
navigator.storage.persist().then((persistent) => {
if (persistent) {
console.log("Storage will not be cleared except by explicit user action");
} else {
console.log("Storage may be cleared by the UA under storage pressure.");
}
});
}
from idb.
We've been using this library for several years but recently in the last 12 months or so have had users reporting total data loss scenarios where they have added information to the database but then upon revisiting the app a few days later everything has gone. Initially we thought it could be user error but the problem seems to be fairly constant in that it continues to be reported and it is completely impossible to replicate or debug.
As per usual as users are not always great at reporting the issues or being particularly accurate with their descriptions but we are beginning to feel that there is an issue with the persistence of data within the IndexedDb storage. We are now at the point where we feel we need to completely remove the offline capability of the app and return to a client/server get/request approach to persisting data and abandon our offline feature.
Has anybody else had issues with data loss like this?
Has anybody got any suggestions as to how we could monitor or trace activity in an attempt to diagnose the issue?
from idb.
Related Issues (20)
- Typescript: cannot compose schema from multiple files HOT 1
- cannot delete particular data in store using IDBKeyRange and cursor. HOT 4
- idb does not detect changes HOT 1
- index.count and db.countFromIndex doesnt work in safari HOT 5
- Open Is Still Successful If Upgrade Throws Exception
- How to use it in a REPL? HOT 1
- Consider adding TypeDoc?
- Add support for Typescript 5.2's `using` keyword
- No able create more the 5 table object in Indexdb
- egronomic way to provide schema via JSDoc
- ConstraintError: Key already exists in the object store. HOT 2
- Not able to import openDB from idb/with-async-ittr in Ver 8
- Comment confusing `unlisten`
- delete only takes key as string but autoincremented keys are numbers HOT 1
- When I try to use main.js in my app I get a referenc eerror-
- DeleteDB should call Close()
- How order for getAllFromIndex
- TS declaration error: Type 'IndexNames<DBTypes, StoreName>' does not satisfy the constraint 'string' HOT 5
- Types exports are incorrect in package.json
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from idb.