angular-localForage icon indicating copy to clipboard operation
angular-localForage copied to clipboard

Cannot read property 'transaction' of undefined

Open RyanP13 opened this issue 9 years ago • 4 comments

I am getting this issue in my angular application.

The local forage provider is configured in the config block like so:

            $localForageProvider.config({
                driver: localforage.LOCALSTORAGE,
                name: 'ttn',
                storeName: 'keyvaluepairs'
            });

Once a user is logged in there is a browser refresh timer which triggers on an hourly basis.

When that happens the config block will run again and throw the following error in the localforage JS file because once logged in we try to resolve the logged in user on that route. It seems from localforage JS that in line 1186:

var store = dbInfo.db.transaction(dbInfo.storeName, 'readonly')

The db is not yet defined. When i check that the data is there in local storage from the window object it is definitely stored there.

Is this expected behaviour?

RyanP13 avatar Mar 03 '16 05:03 RyanP13

Same issue here. It happens when I use $localforage on a promisified resolved service.

Caligone avatar May 09 '16 13:05 Caligone

Same problem here with a very similar setup to RyanP13.

CreatedByVictor avatar May 24 '16 20:05 CreatedByVictor

For what it is worth i solved this in a hacky way by checking the window.localStorage object to see if my storage key was present. If not found then define the store. Not pretty:

        function configureLocalForage(){

            var isStoreDefined = false;

            for (var key in window.localStorage){
                if(key.match(/^ttn\/[a-z0-9]*/gmi) !== null){
                    isStoreDefined = true;
                }
            }

            if(!isStoreDefined){
                $localForageProvider.config({
                    driver: localforage.LOCALSTORAGE,
                    name: 'ttn',
                    storeName: 'keyvaluepairs'
                });
            }

        }

RyanP13 avatar May 25 '16 02:05 RyanP13

Can someone make a minimal reproduction case for this? I'm not sure I follow the issue, as I've never seen this in my own usage.

scotttrinh avatar Sep 22 '17 01:09 scotttrinh