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

Error: No available storage method found #722

Open
jasan-s opened this issue Aug 14, 2017 · 23 comments
Open

Error: No available storage method found #722

jasan-s opened this issue Aug 14, 2017 · 23 comments

Comments

@jasan-s
Copy link

jasan-s commented Aug 14, 2017

I am still getting an error : (node:12884) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 6): Error: No available storage method found. I'm using v1.50
Update: The error actually only occurs when using react-snapshot lib

@lieut-data
Copy link

Assuming we have similar root causes, I traced the unhandled promise rejection warning to the following:

function executeTwoCallbacks(promise, callback, errorCallback) {
if (typeof callback === 'function') {
promise.then(callback);
}
if (typeof errorCallback === 'function') {
promise.catch(errorCallback);
}
}
export default executeTwoCallbacks;

The unhandled promise rejection comes from the promise returned (but ignored) by invoking .then above. In my case, this path was reached by passing a callback to localforage.ready:

localforage.ready(() => {
    // ...
}).catch(() => {
    // ...
});

I can work around this by instead relying exclusively on the promise, sidestepping the bug in executeTwoCallbacks above:

localforage.ready().then(() => {
    // ...
}).catch(() => {
    // ...
});

To fix executeTwoCallbacks properly, I suspect one would want to preserve the promise chain back to all the callers of this utility method, returning the promise at each step vs. branching as above.

lieut-data added a commit to mattermost/mattermost-webapp that referenced this issue Mar 28, 2018
lieut-data added a commit to mattermost/mattermost-webapp that referenced this issue Apr 3, 2018
* remove "Network status set to (true|false)" message

This was originally added in a bid to track down a now resolved issue,
and thus is no longer needed.

* work around UnhandledPromiseRejectionWarning errors from localforage

See localForage/localForage#722.

* fix missing props in tests

* skip passing showEmailAddress from ProfilePopver to the Popover bootstrap component

* eliminate unneeded warning in getPrefix

* fix spurious state in rhs reducer tests

* leverage jest-canvas-mock to avoid warnings from the doughnut chart

* fail the build on console messages

* Revert "skip passing showEmailAddress from ProfilePopver to the Popover bootstrap component"

This reverts commit 73b5fcb.

* just remove showEmailAddress in the profile popover unit tests

* define STORE_REHYDRATION_FAILED locally vs. in mattermost-redux, for now

* fix recently broken unit tests
@951565664
Copy link

Is this a custom errorMessage? What does this error message mean? My monitoring system caught this error, but I don't know how to reproduce it.

@951565664
Copy link

I want to know when this problem will occur?

@thgreasi
Copy link
Member

thgreasi commented Mar 29, 2019 via email

@AndrewBogdanovTSS
Copy link

@thgreasi localForage-memoryStorageDriver looks interesting but documentation doesn't provide a full example of using it. Maybe you could provide an example of how a situation of not having any local storage options can be handled with the help of it? Can it be somehow picked up by localForage automatically? As far as I understand the logic behind using it is:

  1. Detect if any storage option is supported.
  2. If not - activate localForage-memoryStorageDriver
    Should these steps be done manually or it will be handled by localForage automatically after adding a dependency?

My Sentry system also tracks this issue for a lot of users but I can't understand what they had to do in order to get such error? From my point of view - it's really not that easy to turn off all the storing mechanisms in modern browsers nevertheless I'm getting this issue from users with Chrome, Safari and Firefox, all recent browser versions.
The error is triggered in this part of the code:

                self._driver = driver._driver;
                setDriverToConfig();
                self._wrapLibraryMethodsWithReady();
                self._initDriver = initDriver(supportedDrivers);
            });
        })["catch"](function () {
            setDriverToConfig();
            var error = new Error('No available storage method found.'); // This line triggers an error
            self._driverSet = Promise$1.reject(error);
            return self._driverSet;
        });

@AndrewBogdanovTSS
Copy link

I was able to reproduce the issue by manually disabling Cookies in the global Chrome settings https://take.ms/nXAWX
@thgreasi is there a way to detect whether storage options are available in localForage?

@Chris1234567899
Copy link

Same issue here. In my case, some clients probably are using some plugin or addon in firefox that blocks cookies and therefore breaks localforage.

For a temporal workaround I added
https://www.npmjs.com/package/localforage-driver-memory
to the driver list.
At least the app does not crash then and I can show them some popup warning to deactivate their plugin.

Waiting for a "real" fix though ;-)

@AndrewBogdanovTSS
Copy link

@Chris1234567899 could you share your setup regarding localforage-driver-memory ? Do you import it with a static import or it can be dynamically imported only for users that doesn't allow cookies?

@salidean
Copy link

@AndrewBogdanovTSS give this a try:

import * as localforage from 'localforage';
import * as memoryDriver from 'localforage-driver-memory';
 
localforage.defineDriver(memoryDriver);
localforage.setDriver(memoryDriver._driver);

@Etheryte
Copy link

It would be nice to make this error try-catchable. Our current use case is essentially

import localforage from 'localforage';

let instance: LocalForage;
try {
  instance = localforage.createInstance({ ... });
} catch (error) { ... }

However with this setup, the above error can't be caught.
Users disabling cookies & local storage, using private browsing, etc are all valid use cases and it would be nice to support them.

@AndrewBogdanovTSS
Copy link

@salidean what do you think about such strategy?

import * as localForage from 'localforage'
import * as memoryDriver from 'localforage-driver-memory'

localForage.defineDriver(memoryDriver)
localForage.setDriver([localForage.LOCALSTORAGE, localForage.INDEXEDDB, localForage.WEBSQL, memoryDriver._driver])

I want to fallback to memoryDriver only when all others aren't available

@beshkenadze
Copy link

The error is still valid for SSR :(

@smithki
Copy link

smithki commented Jan 26, 2021

I've encountered this issue during unit tests that depend upon localforage, even with the following snippet:

import * as localforage from 'localforage';
import * as memoryDriver from 'localforage-driver-memory';
 
localforage.defineDriver(memoryDriver);
localforage.setDriver(memoryDriver._driver);

For the life of me I cannot find where the code is throwing, but I have a feeling the error is uncatchable without modifying the localforage source code.

@BernardA
Copy link

Just to second @beshkenadze as I still have the issue after implementing the proposal from @AndrewBogdanovTSS on my Next js app.

@waleedarshad
Copy link

localforage

@BernardA have you found any solution. What workaround did you try out?

@BernardA
Copy link

@waleedarshad This was many moons ago. I can't recall at all. Sorry.

@beshkenadze
Copy link

@waleedarshad you have to disable a persist reducer for the server-side rendering, something like that:

const persistedReducer = persistReducer(
    persistOptions,
    offlineEnhanceReducer(rootReducer),
);

if (isServer) {
    store = createStore(
        rootReducer,
        preloadedState,
        applyMiddleware(sagaMiddleware, offlineMiddleware),
    );
} else {
    store = createStore(
        persistedReducer,
        preloadedState,
        composeEnhancers(
            offlineEnhanceStore,
            applyMiddleware(sagaMiddleware, offlineMiddleware),
        ),
    );
}

@sherl0cks
Copy link

I hit this issue when using aws amplify datastore. At one point I scoured their code and found that the root cause was that jsdom does not provide indexeddb. You can use https://www.npmjs.com/package/fake-indexeddb to solve this. So long as you import 'fake-indexeddb/auto'; before the code instantiating localforage runs, it should alleviate the problem.

@yangfei4913438
Copy link

I'm using nextjs, and I'm getting the same error. But I found out that it was caused by a timed task using localforage while running on the server side. Once I disabled the timer from running on the server side, the error went away.

@gaozhidf
Copy link

gaozhidf commented Nov 15, 2022

you can define a custom driver like emptyLocalForageDriver, and set it as default when window is undefined.

const emptyLocalForageDriver = {
  // ref: https://localforage.github.io/localForage/#driver-api-definedriver
  _driver: 'emptyLocalForageWrapper',
  _support: true,
  _initStorage: function(options: any) {
      // Custom implementation here...
  },
  clear: function(callback: any) {
      // Custom implementation here...
  },
  getItem: function(key: any, callback: any) {
      // Custom implementation here...
  },
  iterate: function(iteratorCallback: any, successCallback: any) {
      // Custom implementation here...
  },    
  key: function(n: any, callback: any) {
      // Custom implementation here...
  },
  keys: function(callback: any) {
      // Custom implementation here...
  },
  length: function(callback: any) {
      // Custom implementation here...
  },
  removeItem: function(key: any, callback: any) {
      // Custom implementation here...
  },
  setItem: function(key: any, value: any, callback: any) {
      // Custom implementation here...
  }
}

export function setLocalForageDriver(storageType: string) {
  // set storage to https://trytobe.top 
  if (typeof window === "undefined") {
    storageType = "undefined";
  }
  switch (storageType) {
    case "indexeddb":
      // use indexeddb
      localForage.setDriver(localForage.INDEXEDDB);
      break;
    case "localstorage":
      // use localstorage
      localForage.setDriver(localForage.LOCALSTORAGE);
      break;
    default:
      localForage.defineDriver(emptyLocalForageDriver as LocalForageDriver);
      localForage.setDriver('emptyLocalForageWrapper');
      break;
  }
}

@abdulsalamcodes
Copy link

abdulsalamcodes commented Jul 31, 2023

I hit this issue when using aws amplify datastore. At one point I scoured their code and found that the root cause was that jsdom does not provide indexeddb. You can use https://www.npmjs.com/package/fake-indexeddb to solve this. So long as you import 'fake-indexeddb/auto'; before the code instantiating localforage runs, it should alleviate the problem.

wow, thanks @sherl0cks.
This solution works for me.

@julianCast
Copy link

julianCast commented Oct 6, 2023

@beshkenadze

@waleedarshad you have to disable a persist reducer for the server-side rendering, something like that:

Hi! Does this mean is an issue between localforage and SSR? Can you expand ?

The only way I can reproduce this is by blocking site data storing from the browser, but seeing so many issues I don't think that many users disabled it. Is there another reason this could be happening? Thank you!

@wangmeijian
Copy link

The error is still valid for window chrome V123.0.6312.59(64bit) :(

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