refactor(web): use singular crossOriginStorage.requestFileHandle()#188010
refactor(web): use singular crossOriginStorage.requestFileHandle()#188010tomayac wants to merge 4 commits into
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
There was a problem hiding this comment.
Code Review
This pull request updates the WASM instantiator to support Cross-Origin Storage (COS) by attempting to retrieve and cache WASM modules using their hashes. Feedback points out potential TypeError risks: one when checking filename.includes('/') if filename is undefined, and another when using the in operator on navigator.crossOriginStorage if it is null or undefined. Both issues can be resolved using optional chaining as suggested.
| export const createWasmInstantiator = (url, filename) => { | ||
| const wasmHashes = window._flutter?.buildConfig?.wasmHashes; | ||
| let hash = wasmHashes?.[filename]; | ||
| if (!hash && filename.includes('/')) { |
There was a problem hiding this comment.
If filename is not provided (which is possible since the function was previously called with only url), filename will be undefined. Calling filename.includes('/') will then throw a TypeError. Use optional chaining to safely check if filename includes a slash.
| if (!hash && filename.includes('/')) { | |
| if (!hash && filename?.includes('/')) { |
| hash = wasmHashes?.[basename]; | ||
| } | ||
|
|
||
| const supportsCrossOriginStorage = 'crossOriginStorage' in navigator && 'requestFileHandle' in navigator.crossOriginStorage; |
There was a problem hiding this comment.
The feature detection check can be simplified and made safer using optional chaining. If navigator.crossOriginStorage is ever defined but resolved to null or undefined (e.g., due to security contexts or mock environments), using the in operator on it would throw a TypeError.
| const supportsCrossOriginStorage = 'crossOriginStorage' in navigator && 'requestFileHandle' in navigator.crossOriginStorage; | |
| const supportsCrossOriginStorage = !!navigator.crossOriginStorage?.requestFileHandle; |
References
- Suggest simplification and refactoring to enhance readability and maintainability. (link)
|
Looks like we need to do a rebase dance |
Switch to the new singular API as adopted in: WICG/cross-origin-storage#61
ac9a210 to
e3f3b0d
Compare
|
Thanks, @kevmoo. Rebased. |
|
When will there be a chrome version that supports this? |
|
autosubmit label was removed for flutter/flutter/188010, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.
|
I don't know, but there's a lot of work happening to make it happen |
|
Do we risk CRASHES in the overlap? That we certainly want to avoid. @tomayac |
|
autosubmit label was removed for flutter/flutter/188010, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label. |
Replace the NotAllowedError / NotFoundError branches with a single bare catch that silently falls through to the network fetch path. This makes the code robust against any future renaming of the error (see WICG/cross-origin-storage#62).
|
autosubmit label was removed for flutter/flutter/188010, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label. |

Switches from the deprecated plural
requestFileHandles([hash])to the new singularrequestFileHandle(hash)API, which returns aFileSystemFileHandledirectly rather than a single-element array. Also updates the feature-detection check accordingly ('requestFileHandle' in navigator.crossOriginStorage).The rename was adopted in the COS spec: WICG/cross-origin-storage#61