-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: WASM DotnetHostBuilder assembly loading progress callback #93941
Comments
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsBackground and motivationThe WASM runtime can take a while to load for certain kinds of apps. To provide a better experience for the user using the application, it can be useful to show a loading indicator. ASP.NET Core Blazor did this (at least it did in .NET 7 when I was last investigating this, although looks like it may not be the case now), but it had to manually instantiate the web assembly module in order to achieve this. Currently, there is no public API available on the This is already possible by using the internal API Proposalinterface DotnetHostBuilder {
//exact naming TDB
//parameters currently match those provided to the `onDownloadResourceProgress` callback available when calling `createDotnetRuntime`
withDownloadResourceProgress(loaded: number, total: number): DotnetHostBuilder;
} Currently, using API Usageconst runtime = await dotnet
.withDownloadResourceProgress(updateProgress)
//...other configuration
.create();
function updateProgress(loaded: number, total: number) {
//do something with the information
} Alternative Designs
RisksLow - the API already exists, this would just be exposing it for use in a more user friendly manner.
|
Thank you for the proposal. It is reasonable to expose the callback with public API. I have fixed the propsal API typescript definition so the parameter is a callback. |
cc @pavelsavara |
I'd be happy to contribute a PR if it would be accepted, unless this need to go through API review first? |
PR is welcome! Actually, we don't need API review for JavaScript changes |
I'm thinking it would be much simpler if we had the same behaviour for this method vs the onDownloadResourceProgress callback specified in The proposal above suggests making
runtime/src/mono/wasm/runtime/loader/assets.ts Lines 598 to 612 in 9ad24ae
What do we want to do here? Using the We have a few options:
|
Sorry, I missed the part about total number. We should definitely have just one callback, so We're ok accepting a PR with just the new API and opening an issue for better "total resources" computation |
Ah - I did wonder about the reasoning behind it - makes a bit more sense now. Will leave the existing behaviour as is. |
This issue has been marked |
Background and motivation
The WASM runtime can take a while to load for certain kinds of apps. To provide a better experience for the user using the application, it can be useful to show a loading indicator.
ASP.NET Core Blazor did this (at least it did in .NET 7 when I was last investigating this, although looks like it may not be the case now), but it had to manually instantiate the web assembly module in order to achieve this.
Currently, there is no public API available on the
DotnetHostBuilder
type that enables this scenario. The public, documented approach would require manually looking up the blazor.boot.json file, and then callingcreateDotnetRuntime
using that configuration. However, for less advanced scenarios, it would be useful to have this functionality available on the host builder.This is already possible by using the internal
withModuleConfig API
, and passing in a value to theonDownloadResourceProgress
callback, however this method is internal and not exposed in the typescript type files for the DotnetHostBuilder, making for a bad IDE experience. This method is mentioned in one of the advanced samples here, which is how I discovered it in the first place.API Proposal
Currently, using
onDownloadResourceProgress
, thetotal
parameter does not actually reflect the total number of resources that the runtime needs to load - I suggest that for this user-friendly API we provide that information rather than making the user calculate this number themselves directly from the blazor.boot.json file.API Usage
Alternative Designs
withModuleConfig
publiclyThis is a much more advanced API, allowing access to lower-level emscripten and more control over how the WASM module is instantiated.
withDownloadResourceProgressCallback
withDownloadProgress
withInitializationProgress
Risks
Low - the API already exists, this would just be exposing it for use in a more user friendly manner.
The text was updated successfully, but these errors were encountered: