Skip to content

[browser] Add withDownloadResourceProgress to DotnetHostBuilder - #134498

Merged
maraf merged 2 commits into
dotnet:mainfrom
maraf:maraf/wasm-startup-progress
Sep 24, 2026
Merged

maraf merged 2 commits into
dotnet:mainfrom
maraf:maraf/wasm-startup-progress

Conversation

@maraf

@maraf maraf commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Fixes #93941

Why

onDownloadResourceProgress is honored by the loader, but the only way to supply it is withModuleConfig, which is internal and not part of the public DotnetHostBuilder. Apps have no supported way to observe resource loading during startup.

What

Adds withDownloadResourceProgress(callback?) to the public DotnetHostBuilder, wired to the existing callback. Behavior is unchanged; this only exposes an already-working mechanism.

Added to both loaders, since WasmBasicTestApp is shared by the Mono and CoreCLR Wasm.Build.Tests lanes and the progress tests carry no runtime filter. On Mono it routes through deep_merge_module with the same mono_exit handling as sibling builder methods. The test asset now calls the public method instead of withModuleConfig.

Notes for reviewers

Not on LoaderConfig, which came up in review. Neither config type has any callback field today; callbacks live on DotnetModuleConfig or go through a builder method, as withResourceLoader does. Mono also serializes config to worker threads, and JSON.stringify drops functions silently.

Follow-up, not done here: CoreCLR still assigns to Module, the internal surface this works around. A tidier version would mirror withResourceLoader with a module-level callback in assets.ts. Left out to keep this small; happy to fold in.

Note

This PR description was generated with the assistance of GitHub Copilot.

onDownloadResourceProgress was declared on DotnetModuleConfig, but the
only way to supply it was withModuleConfig, which is internal and not
part of the public DotnetHostBuilder surface. That left no supported way
for apps to observe resource loading during startup.

Add withDownloadResourceProgress(callback) to the public builder in both
the CoreCLR and Mono loaders, and switch the WasmBasicTestApp startup
progress scenario over to it. The test asset is shared by the Mono and
CoreCLR Wasm.Build.Tests lanes, so both loaders need the method.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@maraf maraf added arch-wasm WebAssembly architecture os-browser Browser variant of arch-wasm labels Sep 23, 2026
@maraf maraf added this to the 12.0.0 milestone Sep 23, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@pavelsavara

pavelsavara commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

CoreCLR still assigns to Module, the internal surface this works around.

Let's migrate this and all other dotnet extensions of Module away. It could be follow up PR. Mirroring it for Mono would be fine, but not necessary. I think those changes would rhyme with #132555 and #134527

@JakeYallop

Copy link
Copy Markdown
Contributor

Would this fix #93941?

@maraf maraf changed the title [wasm] Add withDownloadResourceProgress to DotnetHostBuilder [browser] Add withDownloadResourceProgress to DotnetHostBuilder Sep 24, 2026
@maraf
maraf marked this pull request as ready for review September 24, 2026 14:48
Copilot AI lite review requested due to automatic review settings September 24, 2026 14:48

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

No unresolved blocking issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Adds withDownloadResourceProgress to the public DotnetHostBuilder API for both CoreCLR and Mono WebAssembly loaders.

Changes:

  • Adds runtime implementations and TypeScript declarations.
  • Updates the shared test asset to use the public API.
  • Preserves existing callback behavior and Mono error handling.
File Description
src/​native/​libs/​Common/​JavaScript/​types/​public-api.ts CoreCLR public API declaration
src/​native/​libs/​Common/​JavaScript/​loader/​host-builder.ts CoreCLR implementation
src/​native/​libs/​Common/​JavaScript/​loader/​dotnet.d.ts CoreCLR declaration
src/​mono/​wasm/​testassets/​WasmBasicTestApp/​App/​wwwroot/​main.js Uses the new public API
src/​mono/​browser/​runtime/​types/​index.ts Mono public API declaration
src/​mono/​browser/​runtime/​loader/​run.ts Mono implementation
src/​mono/​browser/​runtime/​dotnet.d.ts Mono declaration

Copilot AI review requested due to automatic review settings September 24, 2026 14:54

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The reviewed changes expose existing behavior consistently across both loaders with no unresolved issues.

Review effort: Lite
Findings: None

@maraf
maraf enabled auto-merge (squash) September 24, 2026 16:19
@JakeYallop

Copy link
Copy Markdown
Contributor

Is it worth documenting that totalResources can change over time (unless that's changed since I last used this callback) - that feels like very non obvious behaviour for someone using this. It didn't matter as much when it wasn't public API, but it does feel like more of a surprise people are going to run into now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Build-mono os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: WASM DotnetHostBuilder assembly loading progress callback

4 participants