GithubHelp home page GithubHelp logo

Comments (4)

ArnaudValensi avatar ArnaudValensi commented on April 20, 2024 2

You can use this pollyfill to use the localStorage in memory:

(function () {
  function isSupported() {
    var item = 'localStoragePollyfill';
    try {
      localStorage.setItem(item, item);
      localStorage.removeItem(item);
      return true;
    } catch (e) {
      return false;
    }
  }

  if (!isSupported()) {
    try {
      Storage.prototype._data = {};

      Storage.prototype.setItem = function (id, val) {
        return this._data[id] = String(val);
      };

      Storage.prototype.getItem = function (id) {
        return this._data.hasOwnProperty(id) ? this._data[id] : undefined;
      },

      Storage.prototype.removeItem = function (id) {
        return delete this._data[id];
      },

      Storage.prototype.clear = function () {
        return this._data = {};
      }
    } catch (e) {
      console.error('localStorage pollyfill error: ', e);
    }
  }
}());

from history.

mjackson avatar mjackson commented on April 20, 2024

Thanks for reporting this bug, @AndreasHogstrom :)

The solution is probably two-fold:

  1. We should catch the QuotaExceededError and emit a warning instead
  2. We should make sure we are only ever calling saveState when we actually need to (i.e. when there is some state to save, e.g. a call to pushState(null, '/path') shouldn't actually try to saveState)

I think that would give developers the flexibility they need to either a) use state and ignore the warnings for users in incognito mode (or possibly try to detect when someone is in incognito mode and do the right thing) or 2) avoid using state entirely, thereby avoiding the warnings.

Would you care to make a PR @AndreasHogstrom?

from history.

iam4x avatar iam4x commented on April 20, 2024

@mjackson I ran into this today, does a simple in memory storage that polyfill the localStorage can make the trick?

I can drop you a PR with warning emitting for now.

from history.

xwchris avatar xwchris commented on April 20, 2024

Yeah ! Finally I get the solution here~

from history.

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.