angular-async-local-storage: Object store missing in Firefox on very first use

Hi,

we ran into problems with Firefox (not private mode, 60.3.0esr and 66.0 tested):

Error: Uncaught (in promise): NotFoundError: The operation failed because the requested database object could not be found. For example, an object store did not exist but was being opened.

Minimal steps to reproduce: Install angular CLI: npm install @angular/cli, create new project: ng new firefox-IDB-test (with routing, scss as style choosen), install localStorage: npm install @ngx-pwa/local-storage@6. This is the content of the app.component.ts:

import { Component } from '@angular/core';

import { LocalStorage } from '@ngx-pwa/local-storage';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
    public title = 'firefox-IDB-test';

    public constructor(protected localStorage: LocalStorage) {
        this.doIt();
    }

    public async doIt(): Promise<void> {
        let val = await this.localStorage.getItem<string>('myKey').toPromise();
        console.log('Read: ', val);
        if (!val) {
            val = 'Test string';
        }

        try {
            await this.localStorage.setItem('myKey', val).toPromise();
            console.log('set item successfully');
        } catch (e) {
            console.log('Error setting item: ', e);
        }
    }
}

This does nothing more than reading a value and write it back. Expected behaviour: null on first read, 'Test string' on successive reads. Note: This happens not every time, in my case about every 4th try. I clean everything in the storage-tab and reopen the browser.

I traced this a bit down: Sometimes the upgradeneeded is not fired from the IDBOpenDBRequest. This results in a missing object store. In e.g. Chrome or Edge this event is always fired. The docs says that on every version change and DB creation (which is the case here), this event should be fired.

I’m not sure if this is a Firefox bug. If so maybe you can investigate a bit deeper. A possible solution would be to open a versionchange transaction and create the object store again if it does not exist…

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 24 (12 by maintainers)

Most upvoted comments

What about falling back into localStorage or memory?

If the issue was always happening in a specific scenario we could do that, but as the issue happens randomly, it would mean that a user arriving on the app with the issue would have his/her data stored in localStorage, and then the next time he/she opens the app the lib would init with indexedDb and thus data from the previous visit would be missing.

Sorry, I missed https://github.com/cyrilletuzi/angular-async-local-storage/issues/95#issuecomment-498133034. It may be related to https://bugzilla.mozilla.org/show_bug.cgi?id=1423917 because it fits perfectly on bug timeframe.

I thought that my information could be of help since it’s the same exception, but mine seems related specifically to Instagram app, and maybe when it fetches metadata. If I manage to reproduce the issue, I’ll be in touch.