chromiumindexeddbdexie

IndexedDB data is suddenly gone (with Dexie)


I've been using Dexie for a small production app. Today by opening the app I noticed that all the data was gone. I doubt that my app is the culprit, as it doesn't have a way to erase all the data at once.

I can only recall that my browser (Arc, based on Chromium) crashed earlier in the day, so I had to force-quit it.

Therefore I was wondering:

  1. can a browser crash delete all the indexedDB data? If not, what else?
  2. does Dexie offer any way to prevent or recover from that? Did I miss to adhere on a best practice? (I shared my Dexie initialization below.)
  3. Is there any way to recover the data (aside from Dexie) or to check all the indexedDB data stored in the browser? (currently, I can see it in the "Application" tab of the dev tools, but it shows me only the one for the current origin/domain.)

Thanks in advance!


My Dexie implementation:

import Dexie, { Table } from 'dexie'

class CustomDatabase extends Dexie {
    projects!: Table<Project, string>
    versions!: Table<Version, string>
    templates!: Table<Template, string>
    images!: Table<Image, string>

    constructor() {
        super('app-designer')

        this.version(1.4)
            .stores({
                projects: 'id, createdAt',
                versions: 'id, projectId, submitted',
                templates: 'id',
                images: 'id, projectId, createdAt',
            })
            .upgrade((tx) => {
                tx.table('projects')
                    .toCollection()
                    .modify((proj) => {
                        proj.pinnedVersions = proj.pinnedVersions || []
                    })
            })
    }
}

export const db = new CustomDatabase()

Solution

    1. Browsers behave differently but Chrome seem to keep it unless the device is low on disk space - then it may delete it. There's an API StorageManager that can be used to request the database to remain persistent and never evict it. In your case a browser crash could also have made the data corrupt and the browser has choosen to evict it for that reason though.

    2. Dexie offers an addon for exporting and importing data, dexie-export-import but it will be a manual step to export data regurlarly to backup the data. Another option is Dexie Cloud which continously backs up the data and keeps it in sync with the cloud service.

    3. I do not have an answer on this. This is probably a very browser-implementation-specific topic and depends on where the browser stores the data on the hard drive.