Skip to content

Generating a Blazor based custom element with .Net 10 RC2 has two points of failure. #64282

Closed

Description

@MarkStega

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I am creating a Blazor based custom element and have run into several issues. I had a poorly written issue (#64807, now closed) that tried to detail my attempts with .Net 10 RC2. I believe the issues here are apart from the Mono assertion errors that are to be fixed in RTM.

The intent is to create a Blazor custom element that is hosted on a Vite website (so pretty much a javascript website).

Here are the issues encountered:

  1. It appears that the generated blazor.webassembly.{version}.js has a hardcoded reference to dotnet.js (Observed in RC1 & RC2)
  2. The publish output using RC2 is truncated.
  3. Documentation needs a boost

Issues #1 & #2 prevent successful deployment of a Blazor based custom element using .Net 10 RC2.

Issue #3 is to help others avoid the trial and error I went through to get this working.

CC @guardrex Added because of documentation issues

Expected Behavior

I expect to be able to deploy a Blazor based custom element without a lot of trial and error

Steps To Reproduce

I have created a sample project that demonstrates the issues.
The project is in a public repository CustomElementWASM. There are detailed steps to reproduce
the issues in the ReadMe.md file. The main branch exhibits a working Blazor Custom Element with work-arounds for the two observed issues. There are two branches that exhibit the individual errors.

Exceptions (if any)

None

.NET Version

.Net 10 RC2

Anything else?

I am quite OK sharing the repo as a sample app if so desired.

Activity

  1. added
    area-blazor
    on Nov 8, 2025
  2. javiercn commented on Nov 9, 2025

    @javiercn
    Member

    @MarkStega thanks for contacting us.

    The reference to dotnet.js shouldn't be a problem unless there isn't a dotnet.js file on the publish output, which as far as I understand should be there.

    @maraf can you take a look?

  3. javiercn commented on Nov 9, 2025

    @javiercn
    Member

    @MarkStega can you try using the nightly RTM bits?

  4. added
    Needs: Author Feedback
    on Nov 9, 2025
  5. maraf commented on Nov 10, 2025

    @maraf
    Member

    @MarkStega Thank you for details

    Regarding the publish, it is a known issue in RC2. It is fixed for the final .NET 10 release. There is a workaround for RC2, see #63970 (comment).

    Regarding the Vite integrating, .NET on WebAssembly (and Blazor as well) needs some configuration to be friendly with JavaScript tools. There is a demo at https://github.com/maraf/blazor-wasm-react and community standup where I talked about it https://www.youtube.com/watch?v=tAh899Gri4E. I'm looking forward to your feedback.

    @guardrex I'll the issue open in case you'll want discuss the docs here

  6. guardrex commented on Nov 10, 2025

    @guardrex
    Contributor

    Thanks @maraf.

    @MarkStega ... The official sample (the one that we're maintaining in the Blazor samples repo) is at ...

    https://github.com/dotnet/blazor-samples/tree/main/10.0/BlazorWebAssemblyReact

    It's the same sample that @maraf referred to, but it will be maintained each release. It's currently only on Preview 7 packages. It will receive an update to release packages tomorrow (Tuesday, Oct. 11).

    The related article coverage on JS bundler support is at ...

    https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/?view=aspnetcore-10.0&tabs=visual-studio#javascript-bundler-support

    The process for supplying feedback on that article section is to open an issue from the bottom of that article with the Open a documentation issue link. For that sample app (the code specifically), open an issue on the Blazor samples repo.

  7. MarkStega commented on Nov 10, 2025

    @MarkStega
    Author

    @guardrex Thanks, I went ahead and added a documentation issue with some suggestions. I posted that before I saw your update here so the comments about the samples can be safely ignored.

    @javiercn

    • I can confirm that the nightly build that I installed today does in fact resolve the RC2 'truncated' publish issue.
    • I also confirmed that the reference to dotnet.js from blazor.webassembly.{fingerprint}.js still exists
    • And I can state that the builds-table is entirely confusing as all three columns 'point' to the same installer which installs a 10.0.101 SDK and then you have to sort out which package references to use to override the the ones coded in the sdk.

    @maraf Thanks for the links. I have a working solution for Vite that 1) copies the published output 'as is' to the vite public/ _framework and public/_content; 2) 'Patches' the index.html to reference the blazor.webassmbly.{fingerprint}.js if needed; and 3) copies the dotnet.{fingerprint}.js to dotnet.js as the blazor webassembly point to the hardcode name

  8. added
    Needs: Attention 👋
    and removed
    Needs: Author Feedback
    on Nov 10, 2025
  9. maraf commented on Nov 10, 2025

    @maraf
    Member

    I have a working solution for Vite that 1) copies the published output 'as is' to the vite public/ _framework and public/_content; 2) 'Patches' the index.html to reference the blazor.webassmbly.{fingerprint}.js if needed; and 3) copies the dotnet.{fingerprint}.js to dotnet.js as the blazor webassembly point to the hardcode name

    I'm curious why the built-in mechanism from the linked sample doesn't work for you and instead you're doing it manually?

  10. MarkStega commented on Nov 10, 2025

    @MarkStega
    Author

    @maraf I have been "burned" so many times over the years of working with Blazor with cached files in the browser I don't want to turn off fingerprinting. I don't want to spend hours trying to figure out why my changes didn't work when it was a cached CMS.BlazorCustomElements.wasm content. While it does take care of the reference to dotnet.js I'd rather let that one be the non-fingerprinted file since it is relatively static.

  11. maraf commented on Nov 10, 2025

    @maraf
    Member

    I understand the caching concert. That's why the workaround for RC2 contains the part where the URLs get added a unique query string per the app release. But that is just a workaround for RC2, in final .NET 10 the issue is solved.

    Also, it's not true that dotnet.js is static. Since .NET 10 it contains the reference all all needed files.

    Anyway, what I'm curious is why are not using WasmBundlerFriendlyBootConfig=true as in the linked sample and let JavaScript tools / vite process all the Blazor assets the same way is if they were part of your JavaScript app? If you look at the sample build output, you can see there isn't blazor.js nor dotnet.js as rollup is configured in the sample to bundle them into the app JavaScript. That is subject to app configuration, but the important part is that blazor assets are visible to the rollup (or other bundlers)

  12. added
    Needs: Author Feedback
    and removed
    Needs: Attention 👋
    on Nov 11, 2025
  13. 7 remaining items

  14. added
    Needs: Attention 👋
    and removed
    Needs: Author Feedback
    on Nov 13, 2025
  15. maraf commented on Nov 13, 2025

    @maraf
    Member

    I guess my fundamental question is in a scenario where Vite (or other) is the server

    Does it mean that you're not using Vite as JavaScript bundler? Are you using Vite just as a development time server?

  16. MarkStega commented on Nov 14, 2025

    @MarkStega
    Author

    I guess my fundamental question is in a scenario where Vite (or other) is the server

    Does it mean that you're not using Vite as JavaScript bundler? Are you using Vite just as a development time server?

    That is correct, Vite is being used simply as a web server for a Typescript app that uses the Blazor published output in order the render the Blazor Custom element. The app is used as part of our development process and aids in page development for what in the end is a Blazor based server website.

  17. maraf commented on Nov 14, 2025

    @maraf
    Member

    Now I understand, sorry for the confusion in my previous replies.

    In that case you can't fingerprint blazor.webassembly.js and dotnet.js, because there is no place to put importmap to and Blazor part of the application is not post-processed with any JavaScript tooling. We rely on one of these two mechanisms.

  18. added
    Needs: Author Feedback
    and removed
    Needs: Attention 👋
    on Nov 14, 2025
  19. MarkStega commented on Nov 14, 2025

    @MarkStega
    Author

    @maraf Thanks for the clarification. That means that if I want to use the output of the publish and maintain the fingerprinting that I need my manual step of copying the dotnet.{fingerprint}.js to dotnet.js or building a customized loadBootResource script that refers to the fingerprinted version.

    Previously (.Net 8) one could take the output of the publish and have it work when deployed to Github pages or other simple web servers. I'll add a documentation issue on the Deploy to GitHub Pages that it needs to be updated to have the need for either disabling fingerprint generation or to add a post process step.

    It seems like it would have been simple to add a fingerprinted reference to dotnet.js in blazor.webassembly.js but I don't understand enough of the wasm publish to understand why that wasn't feasible.

  20. added
    Needs: Attention 👋
    and removed
    Needs: Author Feedback
    on Nov 14, 2025
  21. davidroth commented on Nov 17, 2025

    @davidroth

    @MarkStega

    Just ran into this after migrating my Blazor WASM standalone app from .NET 8 to .NET 10. After comparing it with the new .net 10 blazor standalone template, I realized that I missed adding the following line in index.html:

    <script type="importmap"></script>

    After adding this line, dotnet publish for a standalone blazor wasm app works as expected, without any additional javascript bundlers being used.

    So I am a bit confused about this discussion here, as it seems to work as expected and this docs issue seems to be a non-issue? dotnet/AspNetCore.Docs#36354 ?

    See inlined importmap in published index.html:

    Image
  22. added this to the 11.0-preview1 milestone on Nov 17, 2025
  23. MarkStega commented on Nov 17, 2025

    @MarkStega
    Author

    @davidroth -- Thanks, but I am publishing a standalone Blazor Custom Element so the project has no index.html. I am assuming that the script line that you indicate causes the index.html to be modified as part of the build. I haven't gotten to migrating a .Net 8 GH Pages project so I'm sure your hint will work for that.

    [EDIT] I'm happy to modify my build process as needed so I am open any insights/help but certainly the process needs to be smoother than it is right now

  24. maraf commented on Jan 21, 2026

    @maraf
    Member

    I believe the questions are answered. The docs have been updated for this scenario. I'm going to close the issue now. Feel free to re-open it or open a new one with further questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Needs: Attention 👋area-blazor

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions