-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
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 runwork 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:8080Exceptions (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:
-
The adapter constructor performs significant work including:
- LINQ operations (
.Select(),.OrderBy(),.ToList()) - Reflection (
.GetTypeInfo().GetCustomAttribute<>()) - Feature creation via
CreateFeature() - Observable collection setup with subscriptions
- LINQ operations (
-
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>