Fix WebWorker template failing in published Blazor WASM apps#65885
Open
ilonatommy wants to merge 5 commits intomainfrom
Open
Fix WebWorker template failing in published Blazor WASM apps#65885ilonatommy wants to merge 5 commits intomainfrom
ilonatommy wants to merge 5 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes the WebWorker project template so it works in published Blazor WebAssembly apps where framework JS files are fingerprinted and resolved via the page’s import map (which workers don’t inherit).
Changes:
- Switch worker startup from a static module import to an
initmessage that provides the resolveddotnet.jsURL, then dynamicallyimport()it in the worker. - Add client-side import map parsing to resolve the fingerprinted
dotnet.jsURL and send it to the worker during creation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/ProjectTemplates/Web.ProjectTemplates/content/WebWorker-CSharp/wwwroot/dotnet-web-worker.js | Defers .NET runtime loading until an init message provides the correct dotnet.js URL; uses dynamic import. |
| src/ProjectTemplates/Web.ProjectTemplates/content/WebWorker-CSharp/wwwroot/dotnet-web-worker-client.js | Resolves dotnet.js via the document import map and posts it to the worker as part of initialization. |
...tTemplates/Web.ProjectTemplates/content/WebWorker-CSharp/wwwroot/dotnet-web-worker-client.js
Outdated
Show resolved
Hide resolved
src/ProjectTemplates/Web.ProjectTemplates/content/WebWorker-CSharp/wwwroot/dotnet-web-worker.js
Outdated
Show resolved
Hide resolved
...tTemplates/Web.ProjectTemplates/content/WebWorker-CSharp/wwwroot/dotnet-web-worker-client.js
Show resolved
Hide resolved
…printed asset resolution to fail.
d81bf17 to
c4a84c1
Compare
This was referenced Mar 20, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Web Workers do not inherit the page's import map, causing fingerprinted asset resolution to fail.
During dotnet publish, Blazor WebAssembly apps fingerprint framework JavaScript files. The non-fingerprinted files do not exist in the published output.
index.htmlcontains an ES Module Import Map that maps the old names to the new ones. It did not fail ondotnet run(WebWorkerTemplate_CanInvokeMethods) because then we do not fingerprint.Web Workers are separate JavaScript execution contexts. Per HTML spec they do not inherit parent page's import map. There is an issue with proposal of fixing it: whatwg/html#8173. but without much activity.
Description
Client reads the page's import map, resolves the fingerprinted URL, and passes it to the Worker via
postMessage. Worker uses dynamicimport()instead of static one.This PR is adding tests that run published app.
Fixes #65820