question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lazy loaded `BlazorCustomElements.js` file does not adhere to the `loadBootResource` configuration

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Hi guys,

Since .NET 7 is out, I’ve been test driving Blazor WASM to see how to use it in combination with other frameworks.

I’ve configured the following to be able to point the loading of resources to a specific server. https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/startup?view=aspnetcore-7.0#load-boot-resources

Which works nicely.

I’m now using the Microsoft.AspNetCore.Components.CustomElements nuget package to get CustomElements to work. Initially you had to reference the script manually:

<script src="_content/Microsoft.AspNetCore.Components.CustomElements/BlazorCustomElements.js"></script>

But since .NET 7 has been released it’s lazy loaded by ASP.NET. Which is awesome. The only problem is: it uses the URL of the server you are on, to lazy load the file, while it should be respecting the loadBootResource configuration.

Which is a problem for me, as I’m depending on the loadBootResource function to get the WASM files from another server, for example a CDN.

Is that something you guys can fix?

cc: @guardrex https://github.com/dotnet/AspNetCore.Docs/issues/27638

Expected Behavior

Loading the JS for CustomElements should respect the loadBootResource configuration.

Steps To Reproduce

  1. Create a Blazor WASM client app
  2. Create a simple webserver that loads the Blazor script with autostart="false" and add the following bootstrapping lines:
Blazor.start({
        loadBootResource: function (type, name, defaultUri, integrity) {
          return 'https://localhost:8088/' + defaultUri`;
        }
      });
  1. Install the CustomElements nuget and implement a basic customelement.
  2. Try loading the basic webserver with the customelement and blazor script.

Exceptions (if any)

No response

.NET Version

7

Anything else?

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SteveSandersonMScommented, Nov 17, 2022

I’ve filed an issue describing this as a general feature request: https://github.com/dotnet/aspnetcore/issues/45148

A more practical solution for you in the short term would be to implement a service worker that will let you override how all static resources are fetched.

0reactions
martinlingstuylcommented, Nov 17, 2022

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lazy load assemblies in ASP.NET Core Blazor ...
Learn how to configure Blazor startup. Learn how to interact with JavaScript in Blazor apps. Tips for increasing performance in ASP.NET Core ...
Read more >
How to import a blazor custom element in another JS ...
The following describes how I resolved an issue similar to yours: trying to register a custom element, the client not rendering the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found