electric-sql / pglite

Lightweight Postgres packaged as WASM into a TypeScript library for the browser, Node.js, Bun and Deno
https://electric-sql.com
Apache License 2.0
4.76k stars 81 forks source link

Fix invalid storage in webworker #67

Closed JfrAziz closed 3 months ago

JfrAziz commented 3 months ago

I found bug when using storage in web worker, it always fallback to nodefs no matter what storage we use. turns out, when we initialize PGLiteWorker, we parse dataDir

const { dataDir: dir, fsType } = parseDataDir(dataDir);
this.dataDir = dir;

now dataDir is the parsed value, for example from idb://my-database to only /my-database without idb://. then when we initialize the worker, we are using parsed value instead the the raw value, and this value will be parsed again in PGLite

async #init() {
    await this.#worker.init(this.dataDir, { debug: this.debug });
    this.#ready = true;
}

so no mattter what storage used in web worker, it's always using nodefs, because we always parsing the parsed value to PGLite