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.56k stars 10.05k forks source link

Include javascript files associated with Blazor components when using MapStaticAssets #59038

Open jofford opened 6 days ago

jofford commented 6 days ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

I noticed that javascript files associated with Blazor components are not being included as static assets in .NET 9 after calling MapStaticAssets(). It'd be great to get these automatically fingerprinted with an immutable cache-control as well. Loving static assets otherwise!

I generally locate javascript files associated with Blazor components in the same folder and load the module as follows. module = await js.InvokeAsync<IJSObjectReference>("import", "./_content/MyRazorComponentLibrary/Components/MyComponent.razor.js")

I tried simply moving MyComponent.razor.js to "wwwroot\js" and loading the module from there however I then ran into the following error. error BLAZOR106: The JS module file '----\wwwroot\js\MyComponent.razor.js' was defined but no associated razor component or view was found for it.

Describe the solution you'd like

Automatically include all javascript files associated with Blazor components as static assets by default

Additional context

No response

javiercn commented 6 days ago

@jofford thanks for contacting us.

Seems that we forgot to pass in the flag to fingerprint assets https://github.com/dotnet/sdk/blob/e77262d3ff2b54f3dd3e5c857b49d27a616298d7/src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.JSModules.targets#L101

andrewrauber commented 4 days ago

@javiercn This is causing us major problems with stale scripts. Is there a way to work around this while we wait for a fix?