Skip to content

refactor(web): use singular crossOriginStorage.requestFileHandle()#188010

Open
tomayac wants to merge 4 commits into
flutter:masterfrom
tomayac:refactor/cos-singular-requestFileHandle
Open

refactor(web): use singular crossOriginStorage.requestFileHandle()#188010
tomayac wants to merge 4 commits into
flutter:masterfrom
tomayac:refactor/cos-singular-requestFileHandle

Conversation

@tomayac

@tomayac tomayac commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Switches from the deprecated plural requestFileHandles([hash]) to the new singular requestFileHandle(hash) API, which returns a FileSystemFileHandle directly 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

@flutter-dashboard

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. platform-web Web applications specifically team-web Owned by Web platform team labels Jun 15, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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('/')) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
if (!hash && filename.includes('/')) {
if (!hash && filename?.includes('/')) {

hash = wasmHashes?.[basename];
}

const supportsCrossOriginStorage = 'crossOriginStorage' in navigator && 'requestFileHandle' in navigator.crossOriginStorage;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
const supportsCrossOriginStorage = 'crossOriginStorage' in navigator && 'requestFileHandle' in navigator.crossOriginStorage;
const supportsCrossOriginStorage = !!navigator.crossOriginStorage?.requestFileHandle;
References
  1. Suggest simplification and refactoring to enhance readability and maintainability. (link)

@kevmoo

kevmoo commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Looks like we need to do a rebase dance

@tomayac tomayac force-pushed the refactor/cos-singular-requestFileHandle branch from ac9a210 to e3f3b0d Compare June 15, 2026 16:47
@tomayac

tomayac commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, @kevmoo. Rebased.

@kevmoo

kevmoo commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

When will there be a chrome version that supports this?

kevmoo
kevmoo previously approved these changes Jun 15, 2026
@kevmoo kevmoo added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 15, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 15, 2026
@auto-submit

auto-submit Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

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.

  • Merge guidelines: A PR needs at least one approved review if the author is already part of flutter-hackers or two member reviews if the author is not a member of flutter-hackers before re-applying the autosubmit label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@tomayac

tomayac commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

When will there be a chrome version that supports this?

I don't know, but there's a lot of work happening to make it happen ;-). You'll hear it first once it can be tested natively. For now, the extension was already updated so it accepts both variants, the singular (new) and the plural (old) version of the API, so we don't break any site.

mdebbar
mdebbar previously approved these changes Jun 16, 2026
@kevmoo

kevmoo commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Do we risk CRASHES in the overlap? That we certainly want to avoid. @tomayac

@tomayac

tomayac commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Do we risk CRASHES in the overlap? That we certainly want to avoid. @tomayac

Nope. I tested locally for both variants and it all worked fine. All tests are green.

@kevmoo kevmoo added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 16, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 17, 2026
@auto-submit

auto-submit Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

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).
@tomayac tomayac dismissed stale reviews from mdebbar and kevmoo via 9f4c303 June 18, 2026 15:49
@mdebbar mdebbar added the CICD Run CI/CD label Jun 24, 2026

@yjbanov yjbanov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mdebbar mdebbar added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 24, 2026
@auto-submit

auto-submit Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

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.

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-web Web applications specifically team-web Owned by Web platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants