Fix WebWorker template failing in published Blazor WASM apps#65885
Merged
ilonatommy merged 9 commits intomainfrom Mar 24, 2026
Merged
Fix WebWorker template failing in published Blazor WASM apps#65885ilonatommy merged 9 commits intomainfrom
ilonatommy merged 9 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
maraf
reviewed
Mar 23, 2026
...tTemplates/Web.ProjectTemplates/content/WebWorker-CSharp/wwwroot/dotnet-web-worker-client.js
Outdated
Show resolved
Hide resolved
javiercn
reviewed
Mar 23, 2026
src/ProjectTemplates/Web.ProjectTemplates/content/WebWorker-CSharp/wwwroot/dotnet-web-worker.js
Show resolved
Hide resolved
javiercn
approved these changes
Mar 23, 2026
maraf
approved these changes
Mar 23, 2026
wtgodbe
added a commit
that referenced
this pull request
Mar 23, 2026
Re-quarantine RazorViews_AreUpdatedOnChange and RazorPages_AreUpdatedOnChange in RazorBuildTest. These were unquarantined in #65864 but are still flaking across unrelated PRs (e.g. #65885). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: William Godbe <wigodbe@microsoft.com>
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
This was referenced Apr 1, 2026
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
dotnet-web-worker-client.js- Usesimport.meta.resolve()on the main thread to resolve_framework/dotnet.jsthrough the browser's native import map resolution.The resolved (fingerprinted) URL is passed to the Worker via
postMessage. No DOM parsing or JSON manipulation needed.dotnet-web-worker.js- Replaces staticimport { dotnet } from '../../_framework/dotnet.js'with message-driven initialization using dynamicimport()with the resolved URL.import.meta.resolve()is supported in Chrome 105+, Firefox 106+, Safari 16.4+.This PR is adding tests that run published app.
Fixes #65820