fix(services/opfs): support OPFS in web workers - #8319
Open
jccampagne wants to merge 3 commits into
Open
jccampagne wants to merge 3 commits into
jccampagne wants to merge 3 commits into
Conversation
The OPFS service resolved the storage manager through `web_sys::window().unwrap()`, which panics in a web worker because there is no `window` there, even though `navigator.storage.getDirectory()` is available on `WorkerNavigator`. Resolve `navigator` from the current global scope instead: `Window` on the main thread, `WorkerGlobalScope` in workers. Any other global scope returns `ErrorKind::Unsupported` instead of panicking. The OPFS edge tests gain a `worker` feature that runs the same suite in a dedicated worker, and no longer call the removed `.finish()` after `Operator::from_config`.fix(services/opfs): support OPFS in web workers The OPFS service resolved the storage manager through `web_sys::window().unwrap()`, which panics in a web worker because there is no `window` there, even though `navigator.storage.getDirectory()` is available on `WorkerNavigator`. Resolve `navigator` from the current global scope instead: `Window` on the main thread, `WorkerGlobalScope` in workers. Any other global scope returns `ErrorKind::Unsupported` instead of panicking. The OPFS edge tests gain a `worker` feature that runs the same suite in a dedicated worker, and no longer call the removed `.finish()` after `Operator::from_config`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Also updated the call to
Operator::from_config(no more.finish).Which issue does this PR close?
Closes #8318
Rationale for this change
OPFS should be usable from web workers too.
What changes are included in this PR?
Are there any user-facing changes?
Fix issue: #8318
The OPFS service resolved the storage manager through
web_sys::window().unwrap(), which panics in a web worker because there is nowindowthere, even thoughnavigator.storage.getDirectory()is available onWorkerNavigator.Change to resolve
navigatorfrom the current global scope instead:Windowon the main threadWorkerGlobalScopein workers.ErrorKind::Unsupportedinstead of panicking.The OPFS edge tests gain a
workerfeature that runs the same suite in a dedicated worker, and no longer call the removed.finish()fromOperator::from_configBreaking changes
AI Usage Statement
Yes, used ClaudeCode to check.