Skip to content

.NET 10 Blazor WASM hang #64765

@rsuk-mb

Description

@rsuk-mb

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When running Handlebars.Net in .NET 10 Blazor WebAssembly (Release build, published), repeatedly calling Handlebars.Compile() causes the browser to hang completely after a variable number of iterations (typically between 1-500 calls).

Key observations:

  • Only occurs in Release published builds - Debug mode and dotnet run work fine
  • Iteration count varies - Hangs occur anywhere from 1 to 500+ iterations
  • Browser completely freezes - No errors thrown, UI becomes unresponsive
  • Works fine in .NET 8 - Same code runs indefinitely in .NET 8 Blazor WASM

The variable iteration count before hang suggests this may be related to:

  • Tiered compilation / Jiterpreter optimization
  • Memory pressure triggering problematic GC behavior
  • WASM runtime optimization of hot code paths

Posting here as seems likely this is a .NET 10 WASM runtime regression rather than a Handlebars.Net issue specifically.


A minimal reproduction repository is available. Happy to provide additional debugging information or test potential fixes.

Expected Behavior

Handlebars.Compile() should be callable indefinitely without causing browser hangs, consistent with behavior in:

  • .NET 8 Blazor WASM
  • .NET 10 server-side / console applications
  • Debug builds

Steps To Reproduce

// Minimal reproduction - Blazor WASM page
@page "/"
@using HandlebarsDotNet

<h1>Handlebars WASM Hang Test</h1>
<p>Iterations: @_count</p>
<button @onclick="RunTest">Start Test</button>

@code {
    private int _count;
    private static readonly IHandlebars Hb = Handlebars.Create();

    private async Task RunTest()
    {
        while (true)
        {
            _count++;

            // This call eventually hangs the browser
            var template = Hb.Compile("Hello {{name}}!");
            var result = template(new { name = "World" });

            StateHasChanged();
            await Task.Delay(1);
        }
    }
}

Critical: Must be tested as a published Release build:

dotnet publish -c Release
cd bin/Release/net10.0/publish/wwwroot
npx http-server -p 8080 -c-1
# Open http://localhost:8080

Exceptions (if any)

None

.NET Version

10.0.101

Anything else?

Investigation findings:

Through extensive debugging with skip flags at various points in the compilation pipeline, we identified that the hang occurs during the creation of HandlebarsConfigurationAdapter in HandlebarsEnvironment.Compile(). Specifically:

  1. The adapter constructor performs significant work including:

    • LINQ operations (.Select(), .OrderBy(), .ToList())
    • Reflection (.GetTypeInfo().GetCustomAttribute<>())
    • Feature creation via CreateFeature()
    • Observable collection setup with subscriptions
  2. A workaround that caches the configuration adapter (avoiding recreation on each compile) delays but does not fully prevent the hang.

Attempted mitigations (none resolved the issue):

  • <WasmEnableJiterpreter>false</WasmEnableJiterpreter>
  • <TieredPGO>false</TieredPGO>
  • <RunAOTCompilation>false</RunAOTCompilation>
  • <WasmEnableWebcil>false</WasmEnableWebcil>
  • <WasmBuildNative>false</WasmBuildNative>
  • <RunWasmOpt>false</RunWasmOpt>
  • <BlazorWebAssemblyEnableLinking>false</BlazorWebAssemblyEnableLinking>
  • <PublishTrimmed>false</PublishTrimmed>

handlebars-wasm-hang-repro.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions