Skip to content
This repository was archived by the owner on Dec 26, 2025. It is now read-only.
This repository was archived by the owner on Dec 26, 2025. It is now read-only.

[Bug] Exception when using this library with ImportMap #605

@S-Luiten

Description

@S-Luiten

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:

  1. Deploy a web application using v7.1.0 of this library
  2. Update the web application to use v7.3.1 of this library and add <ImportMap /> to App.razor, then redeploy
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingTriageIssue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions