Skip to content

isOpfsSupported breaks if source is transformed #3

@davidisaaclee

Description

@davidisaaclee

isOpfsSupported converts a function to a string to create a JS source string

sqlite-wasm/src/utils.ts

Lines 41 to 46 in 08c341a

const url = URL.createObjectURL(
new Blob(
[`(${inner})().then(postMessage)`],
{ type: 'text/javascript' },
),
)
which is then loaded into a worker.

If this code is run through certain code transforms (e.g. tsc with target of es2015), the inner function's string representation can become invalid worker code. In my project, inner.toString() === 'e', so the resulting worker source was (e)().then(postMessage) (and e's definition is outside of the worker) – attempting to use isOpfsSupported raises an error because e.then is not defined.

I think with target = es2015, any async function would become invalid: demo.


This is an issue for me because I'm using your dialect-wasqlite-worker (which is otherwise great, ty), which has an unskippable check to isOpfsSupported when trying to use OPFS.

I don't need a fix urgently because I'm probably just going to patch dialect-wasqlite-worker to unblock myself (I can assume OPFS is available in my app), but thought I'd bring this up as a potential pitfall.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions