Skip to content

OPFSAdaptiveVFS: load where FileSystemSyncAccessHandle is unavailable - #374

Open
lalexdotcom wants to merge 2 commits into
rhashimoto:masterfrom
lalexdotcom:fix/adaptive-missing-sync-handle
Open

lalexdotcom wants to merge 2 commits into
rhashimoto:masterfrom
lalexdotcom:fix/adaptive-missing-sync-handle

Conversation

@lalexdotcom

Copy link
Copy Markdown
Contributor

What happens

OPFSAdaptiveVFS.js reads globalThis.FileSystemSyncAccessHandle.prototype while the module is evaluated, to detect readwrite-unsafe support. Where the interface does not exist, importing the module throws a TypeError before anything else runs. That is the case:

  • outside a dedicated worker: on a page's main thread, or in Node, for instance a unit test or server-side rendering that imports the module;
  • on a page that is not a secure context (plain http, localhost aside), where browsers withhold OPFS;
  • in browsers older than the interface: Chrome before 102, Chrome for Android before 109, Firefox before 111 (MDN browser-compat-data).

The VFS cannot run there anyway, but importing it should not fail. For example, an application bundles several VFS into one worker and picks one at runtime. Where this interface is missing, it cannot use MemoryVFS or an IndexedDB VFS either, because the whole worker fails to load.

The change

Optional chaining on that read: hasUnsafeAccessHandle is undefined where the interface is missing. Where it exists, nothing changes.

Test

test/OPFSAdaptiveVFS.test.js gains a test that imports the module from the test page, a main thread, where FileSystemSyncAccessHandle is undefined. On master it fails on Chromium and Firefox (Playwright), for example Expected 'can't access property "prototype", globalThis.FileSystemSyncAccessHandle is undefined' to be undefined. With the change, the file's 72 tests pass, 3 runs of 3, on both. The whole suite passes on Chromium: 6158 passed, 0 failed.

Checklist

  • I grant to recipients of this Project distribution a perpetual,
    non-exclusive, royalty-free, irrevocable copyright license to reproduce, prepare
    derivative works of, publicly display, sublicense, and distribute this
    Contribution and such derivative works.
  • I certify that I am legally entitled to grant this license, and that this
    Contribution contains no content requiring a license from any third party.

lalexdotcom and others added 2 commits October 3, 2026 22:13
The module read FileSystemSyncAccessHandle.prototype while it was
evaluated, so importing it threw wherever the interface is missing: on
a main thread, in Node, on a page that is not a secure context, and in
browsers older than the interface. A worker bundling several VFS then
failed to load as a whole.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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 this pull request may close these issues.

1 participant