Skip to content

Example project for the issue #37 in BlazorWasmPreRendering.Build

Notifications You must be signed in to change notification settings

megazyz/Example.PrerenderingWithWorkers

Repository files navigation

Sample project for the issue #37 in BlazorWasmPreRendering.Build.

Steps:

  • Create a new Blazor WebAssembly App using the template in Visual Studio
  • Add package BlazorWasmPreRendering.Build (3.1.0-preview.3)
  • Add package SpawnDev.BlazorJS.WebWorkers (2.2.8)
  • Extract ConfigureServices in program.cs according to BlazorWasmPreRendering docs
  • Register SpawnDev.BlazorJS.WebWorkers services in program.cs
  • Add an example worker (IMyWorker.cs, MyWorker.cs)
  • Inject WebWorkerService to Counter.razor
  • Change IncrementCount() to use the web worker:
private async void IncrementCount()
{
    //currentCount++;
    using var webWorker = await WorkerService.GetWebWorker();
    var myWorker = webWorker.GetService<IMyWorker>();
    var result = await myWorker.Add(currentCount, 1);
}
  • Start the app, and press the Click Me button on the Counter page
  • BlazorWasmPreRendering.Build.lib.module.js throws an exception when the worker starts, because the DOM is not available in web workers:
MONO_WASM: Failed to invoke 'afterStarted' on library initializer '../_content/BlazorWasmPreRendering.Build/BlazorWasmPreRendering.Build.lib.module.js': TypeError: n.createNodeIterator is not a function

About

Example project for the issue #37 in BlazorWasmPreRendering.Build

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published