dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.43k stars 10.02k forks source link

Simplify WebAssembly hot reload capabilities detection #51507

Open MackinnonBuck opened 1 year ago

MackinnonBuck commented 1 year ago

Background

Upon initialization, the dotnet watch tool needs to know the set of available WebAssembly hot reload capabilities before the hot reload session starts. The current mechanism for this relies on the WebAssembly runtime having started up so it can be asked which capabilities it supports. However, in Blazor Web scenarios, WebAssembly runtime startup might be delayed indefinitely, which causes the mechanism to read hot reload capabilities to fail.

We worked around this problem in https://github.com/dotnet/sdk/pull/36195 by having a fallback, default set of capabilities to use if reading capabilities from the WebAssembly runtime fails.

Proposed solution

We could go one of two directions in the future to fully address this issue:

To simplify the Blazor WebAssembly hot reload infrastructure and make the overall hot reload experience less error prone, I propose we go with the 2nd option that simplifies WebAssembly hot reload capabilities detection by having the full set of capabilities be known by the dotnet watch tool without having to dynamically fetch those capabilities from the WebAssembly runtime.

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost commented 10 months ago

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

SteveSandersonMS commented 9 months ago

@lewing @danroth27 We'd like to discuss whether this could be changed in the runtime.

lewing commented 9 months ago

cc @thaystg

lambdageek commented 9 months ago

One idea is that the runtime pack could provide a .props file with a statically known set of default capabilities for a particular version of Mono. those could be consumed by dotnet watch when it is invoked to populate the fallback that is used. That ways there's a single source of truth in the runtime repo. (This would require a bit of work in dotnet/runtime and also in dotnet watch, I think)

I'm assuming that a particular build of the runtime will always advertise the same set of capabilities. That's not entirely true on other platforms (if you turn off the interpreter on Android, the runtime says it doesn't support any edits, for example) but it's always a function of the build-time configuration of the project, not the dynamic environment in which it is executing. So maybe this is still a reasonable approach.

thaystg commented 9 months ago

Not sure if I'm saying something impossible or crazy :). Does dotnet watch have access to System.Private.CoreLib.dll that will be used in the webassembly app? Then it can load it and invoke GetCapabilities https://github.com/dotnet/runtime/blob/2d751cac7311b344c237df3b3c63b33434b52217/src/mono/System.Private.CoreLib/src/System/Reflection/Metadata/MetadataUpdater.cs#L50 If the answer is yes it would not work yet. We would need to change mono GetCapabilities to return this "default capabilities" that can be updated when the runtime is started.

lambdageek commented 9 months ago

Not sure if I'm saying something impossible or crazy :). Does dotnet watch have access to System.Private.CoreLib.dll that will be used in the webassembly app?

Probably

Then it can load it and invoke GetCapabilities https://github.com/dotnet/runtime/blob/2d751cac7311b344c237df3b3c63b33434b52217/src/mono/System.Private.CoreLib/src/System/Reflection/Metadata/MetadataUpdater.cs#L50

This might be difficult to do: you can't load multiple copies of SPC - even if you try to load them into separate assembly load contexts. dotnet watch would have to compile and run a separate test project in the background just to read the capabilities.