Giter VIP home page Giter VIP logo

Comments (2)

dustinbolton avatar dustinbolton commented on June 2, 2024

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.

caboodal avatar caboodal commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.