[browser][coreCLR] Fix download() → create() lifecycle for WASM loader#127383
Merged
pavelsavara merged 5 commits intodotnet:mainfrom Apr 27, 2026
Merged
[browser][coreCLR] Fix download() → create() lifecycle for WASM loader#127383pavelsavara merged 5 commits intodotnet:mainfrom
download() → create() lifecycle for WASM loader#127383pavelsavara merged 5 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Restructures the WASM loader lifecycle to support a two-phase download() → create() flow (including an HTTP-cache-only prefetch mode), and extends coverage to prevent regressions.
Changes:
- Adds loader state tracking so
download()can be followed bycreate()without re-running one-time initialization. - Introduces
download(httpCacheOnly?: boolean)and implements HTTP-cache-only prefetching for boot assets (plus<link rel="prefetch">hints for JS modules). - Extends/introduces WASM build tests and enables the previously-disabled CoreCLR scenario.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/native/libs/Common/JavaScript/types/public-api.ts | Updates the public download(httpCacheOnly?: boolean) API signature and docs. |
| src/native/libs/Common/JavaScript/loader/run.ts | Implements the new lifecycle/state machine and cache-only download path. |
| src/native/libs/Common/JavaScript/loader/host-builder.ts | Wires download(httpCacheOnly?: boolean) through to createRuntime. |
| src/native/libs/Common/JavaScript/loader/dotnet.d.ts | Updates TypeScript declarations for the new download signature. |
| src/native/libs/Common/JavaScript/loader/assets.ts | Adds HTTP-cache-only prefetch implementation and JS module prefetch link hints. |
| src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js | Adds browser test scenarios for download()→create() and download(true)→create(). |
| src/mono/wasm/Wasm.Build.Tests/DownloadThenInitTests.cs | Extends existing test and adds a new test validating the cache-only mode. |
| eng/testing/scenarios/BuildWasmAppsJobsListCoreCLR.txt | Enables DownloadThenInitTests for CoreCLR scenario runs. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
maraf
approved these changes
Apr 27, 2026
Member
maraf
left a comment
There was a problem hiding this comment.
Looks good to me and my copilot 👍
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.
Fixes #124896
The
download()API was broken — callingdownload()followed bycreate()failed because the native module couldn't be re-initialized. This PR restructures thecreateRuntime()flow to properly support the two-phase download→create lifecycle.Changes
Loader core (
run.ts)downloadStarted,downloadedIntoMemory,configInitialized) sodownload()andcreate()can be called sequentially without re-running initialization.onConfigLoaded,modulesAfterConfigLoaded, polyfills, console wiring) now runs exactly once regardless of how many timescreateRuntimeis entered.download()already loaded assets into memory,create()takes a fast path: initialize CoreCLR, fireonDotnetReady, loadmodulesAfterRuntimeReady— skipping redundant downloads.download()calls are a no-op.HTTP-cache-only prefetch mode (
assets.ts)download(httpCacheOnly: true)parameter. When set, resources are fetched into the browser HTTP cache and discarded — no WASM memory is consumed. A subsequentcreate()will re-fetch from cache.prefetchAllResources()enqueues all data assets (assemblies, ICU, VFS, WASM, PDBs, symbols, satellites) and fetches them with throttling (maxParallelDownloads).prefetchJSModuleLinks()injects<link rel="prefetch">hints for JS modules instead of fetching them, since they useimport().prefetchUrl()respectsloadBootResourceCallback, integrity checks, anddisableNoCacheFetch.Public API (
public-api.ts,dotnet.d.ts,host-builder.ts)download()signature updated todownload(httpCacheOnly?: boolean).Tests
NoResourcesReFetchedAfterDownloadFinishedto verifyonConfigLoadedfires duringdownload(), resources are fetched during download, none re-fetched duringcreate(), andcreate()completes.HttpCacheOnlyThenCreateWorkstest coveringdownload(true)→create()withloadBootResourcecallback verification.DownloadThenInitHttpCacheOnlyinmain.js.DownloadThenInitTestsfor CoreCLR inBuildWasmAppsJobsListCoreCLR.txt.