-
-
Notifications
You must be signed in to change notification settings - Fork 192
[Bug] Exception when using this library with ImportMap #605
Description
Describe the bug
.NET 9.0 added a new component ImportMap, which defines the expected hash for the BlazoredModal.razor.js file.
Due to lack of assets fingerprinting using the Assets property, the js file can be retrieved from the browser cache, even when there's a new version (for example when updating this package from v7.1.0 to v7.3.1).
If the js file is served from the browser cache, the hash mismatch will cause an exception.
To Reproduce
Steps to reproduce the behavior:
- Deploy a web application using v7.1.0 of this library
- Update the web application to use v7.3.1 of this library and add
<ImportMap />toApp.razor, then redeploy - Visit the website while the v7.1.0 version of the .js file is still in the browser cache. Note that the exception may not occur for all web browsers, but it should happen when using chrome.
Expected behavior
The library should support .NET 9's built-in cache-busting mechanisms to prevent web browsers from serving an outdated file from cache.
Hosting Model (is this issue happening with a certain hosting model?):
- Blazor Server
Additional context
Exception:
[ERR] Unhandled exception in circuit '{GUID}'.
Microsoft.JSInterop.JSException: Failed to fetch dynamically imported module: https://{BASEURL}/_content/Blazored.Modal/BlazoredModal.razor.js
TypeError: Failed to fetch dynamically imported module: https://{BASEURL}/_content/Blazored.Modal/BlazoredModal.razor.js
at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
at Blazored.Modal.BlazoredModal.OnAfterRenderAsync(Boolean firstRender)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
Solution
Change
_styleFunctions = await JsRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/Blazored.Modal/BlazoredModal.razor.js");to
_styleFunctions = await JsRuntime.InvokeAsync<IJSObjectReference>("import", Assets["./_content/Blazored.Modal/BlazoredModal.razor.js"]);Workaround
Remove <ImportMap /> from App.razor