Repository navigation
[blazor] Fix Web Worker initialization on CoreCLR - #70504
Conversation
Bind only the configured worker assembly's [JSExport] methods instead of also binding the host's main assembly. On CoreCLR, getAssemblyExports throws when the assembly has no generated JS export initializer, which is typical for the host app. Re-enable the WebWorkerTemplateE2ETest cases. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the worker-export lookup change, though the re-enabled browser tests were not run because build prerequisites were missing.
No open issues 🎉
What changed in this PR
Fixes Blazor Web Worker initialization on CoreCLR by avoiding export lookup on a host assembly that may have no [JSExport] methods. This follows the template-test infrastructure’s move away from Mono.
Changes:
- Loads exports only from the configured worker assembly, removing automatic host exports and the main-assembly fallback.
- Re-enables four browser tests covering invocation, error handling, disposal, and invocation after publishing.
The re-enabled repository tests were not run because the required test assembly and local package graph had not been built.
| File | Description |
|---|---|
| src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWebWorker-CSharp/wwwroot/dotnet-web-worker.js | Restricts export lookup to the configured worker assembly. |
| src/ProjectTemplates/test/Templates.Blazor.Tests/WebWorkerTemplateE2ETest.cs | Removes CoreCLR-related skips from four browser tests. |
Review effort: Balanced
|
/review |
There was a problem hiding this comment.
Source-only review of frozen head 75c8f6c791b539245d98734a95ab2f982e9c06b0.
One P2 candidate is published inline with unresolved confidence: the diff removes main-assembly export merging, but the frozen bundle does not contain the target-version-bound runtime contract/source needed to prove the resulting getConfig()/getAssemblyExports() behavior. No verified defect is asserted.
- Guide completion:
docs/CrossCuttingGuidance.mdcompleted its in-scope cross-cutting checks. Runtime, CI, browser, and sample execution were excluded by the source-only policy; security assessment was explicitly out of scope. - Existing feedback: Frozen feedback contained no equivalent supported finding to deduplicate. This is a neutral coverage statement, not an endorsement of prior reviews.
- Unresolved: Exact .NET runtime export-discovery semantics for distinct host and worker assemblies.
- Uncovered: No specialist guide covered Web Worker/runtime template semantics beyond the cross-cutting review.
- Test boundary: Tests and target code were not executed. The re-enabled E2E tests were assessed from source and cover WorkerLib exports, not a distinct host-assembly export.
- Provenance: PR 70504; merge base/base tip
50f5c66e0b4522be2848078a14f418fb74fe59dc; trusted guidance commit50f5c66e0b4522be2848078a14f418fb74fe59dc. Evidence was limited to frozen tracked Git bytes; symlinks, submodules, and LFS targets are inert. Feedback posted after bundle preparation was not observable.
Generated by ASP.NET Core Pull Request Review for #70504 · copilot · gpt56 · 124.6 AIC · ⌖ 22 AIC · ⊞ 18.8K
Comment /review to run again
| workerExports = { ...workerExports, ...await getAssemblyExports(assemblyName) }; | ||
| } | ||
| const { getAssemblyExports } = await dotnet.create(); | ||
| workerExports = { ...await getAssemblyExports(assemblyName) }; |
There was a problem hiding this comment.
P2 · confidence: unresolved
[UNRESOLVED] Host-assembly [JSExport] methods may no longer be callable when WebWorkerClient is supplied by a separate worker library.
Why unresolved: The frozen repository source shows that the merge base loaded and merged mainAssemblyName plus the requested assembly, while this line loads only the requested assembly. However, the bundle does not include a target-version-bound runtime contract, runtime source, or immutable validation artifact proving the exact getConfig()/getAssemblyExports() semantics needed to establish the old/new observable behavior.
Minimal repro: In a host whose main assembly differs from WorkerLib, define a host [JSExport], reference WorkerLib, call WebWorkerClient.CreateAsync(JSRuntime) without an assembly name, then invoke the host export's fully qualified path.
What may go wrong: If the runtime APIs behave as assumed by the previous implementation, the host export is absent and invocation returns Method not found.
Possible fix: Preserve main-assembly exports when a distinct worker assembly is selected, while avoiding export lookup for assemblies that cannot provide exports; otherwise add a binding contract and coverage for the intentional single-assembly behavior.
There was a problem hiding this comment.
This function is intended to be called through the template's C# WebWorkerClient.CreateAsync wrapper. That wrapper always resolves assemblyName—defaulting it to the assembly containing WebWorkerClient—before calling the JavaScript create function. The JavaScript module is an implementation detail; the template doesn't call it directly.
Auto-replied by the GitHub Copilot app
|
Copilot's local review panel found no issues to raise at this commit. Informational - [UNRESOLVED], not blocking (P3): At Posted for informational purposes so the author can confirm the verifier didn't discard or leave unresolved a real finding; this item does not block The existing host-assembly-export concern in discussion 4539519917 was not duplicated. This was a source review, not runtime validation. Human-directed and GitHub Copilot-generated. |
|
✅ No documentation PR was created. Confidence that documentation is needed: 25% No docs needed. This is a bug fix to the Web Worker template initialization, and the existing documentation already describes the resulting behavior. Documentation surfaces considered
|
[blazor] Fix Web Worker initialization on CoreCLR
Fix Web Worker initialization on CoreCLR.
Description
CoreCLR throws when
getAssemblyExportsis called for a host assembly with no[JSExport]methods. Bind only the configured worker assembly and re-enable the fourWebWorkerTemplateE2ETestcases.WebWorkerClient.CreateAsyncsupplies the worker library assembly name by default.This intentionally stops automatically including host-assembly exports and removes the fallback to the main assembly when no assembly name is supplied.
Validation
dotnet build -v q,dotnet run --no-build --urls http://127.0.0.1:5199,node /private/tmp/wwprobe/probe.mjs http://127.0.0.1:5199/webworker-test,dotnet publish -o /private/tmp/wwrepro/pub -v q,cd /private/tmp/wwrepro/pub/wwwroot && python3 -m http.server 5198 --bind 127.0.0.1, andnode probe.mjs http://127.0.0.1:5198/ webworker-test. This browser run was before removal of the fallback, which was not used because the worker assembly name was supplied.node --input-type=modulewith a JavaScript VM probe of the final worker and a simulated runtime: passed. The baseline attempted to bind the host and failed; the final worker bound only the supplied worker assembly, invoked its export, and propagated errors.source activate.sh && dotnet test src/ProjectTemplates/test/Templates.Blazor.Tests/Templates.Blazor.Tests.csproj --no-build --no-restore --filter 'FullyQualifiedName~WebWorkerTemplateE2ETest': blocked because the test assembly and full local package graph have not been built. The four re-enabled repository tests were not run.Fixes: #70502 (follow-up to #70481).
Note
This PR description was generated with the assistance of GitHub Copilot.