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 thrown when DB does not exist and autoload is set to true #178

Closed
gotenxds opened this issue Aug 21, 2020 · 1 comment · Fixed by #179
Closed

Error thrown when DB does not exist and autoload is set to true #178

gotenxds opened this issue Aug 21, 2020 · 1 comment · Fixed by #179

Comments

@gotenxds
Copy link

[X] Bug report
[X] Documentation issue or request

So this is either a bug or just a lack of documentation and me using this wrong.

Current behavior

When using autoload, if the database already exists everything works as expected,
the issue is then on a first time load of the website the DB is yet to be created and loki throws the error

DB ERROR TypeError: The persistence adapter did not load a serialized DB string or object.
    at eval (lokidb.loki.js:5577)

I've debugged it for the last hour, and it does seem like loki is trying to create a new DB if needed, the issue lays in getAppKey function, it receives the newly created catalog and tries to search for the appKey in the store index, but it is not there.

Expected behavior

To work with on first load with autoload on

Minimal reproduction of the problem with instructions

Here is how I Initialize my DB (works perfectly if autoload is off)

const db: Loki | undefined
let loading = false

export default () => {
  if (!db && process.client && !loading) {
    loading = true

    console.log('Initializing DB')

    FullTextSearch.register()
    IndexedStorage.register()
    const lokiDb = new Loki('notAMimic')

    lokiDb.initializePersistence({ adapter: new IndexedStorage(), autosave: true, autoload: true })
      .then(() => {
        db = lokiDb
      })
      .catch((e: Error) => {
        // eslint-disable-next-line no-console
        console.log('DB ERROR', e)
      })
  }

  return db
}

Environment

Latest

Browser/Node version: Chrome 84.0.4147.125

Others:
I doubt It's relevent, but, using typescript with vuejs

@Viatorus
Copy link
Member

Thank you for your bug report. :)

I fixed it in #179. Please have a look.

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

Successfully merging a pull request may close this issue.

2 participants