diff --git a/src/mono/sample/wasm/blazor-frame/Pages/Index.razor b/src/mono/sample/wasm/blazor-frame/Pages/Index.razor index 7b5a15e0e22b1f..a8ac07a85c63db 100644 --- a/src/mono/sample/wasm/blazor-frame/Pages/Index.razor +++ b/src/mono/sample/wasm/blazor-frame/Pages/Index.razor @@ -1,7 +1,15 @@ @page "/" +@inject IJSRuntime JSRuntime Index

Hello, world!

Welcome to your new app. + +@code { + protected override void OnAfterRender(bool firstRender) + { + BenchmarkEvent.Send(JSRuntime, "Rendered Index.razor"); + } +} diff --git a/src/mono/sample/wasm/blazor-frame/wwwroot/frame.js b/src/mono/sample/wasm/blazor-frame/wwwroot/frame.js index 06caaf2733b7c4..322d3eb766b173 100644 --- a/src/mono/sample/wasm/blazor-frame/wwwroot/frame.js +++ b/src/mono/sample/wasm/blazor-frame/wwwroot/frame.js @@ -19,6 +19,13 @@ try { window.addEventListener("pageshow", event => { window.parent.resolveAppStartEvent("pageshow"); }) } + // receive blazor benchmark event and forward it to resolveAppStartEvent + window.receiveBenchmarkEvent = function (name) { + if (window !== window.parent) { + window.parent.resolveAppStartEvent("blazor: " + name); + } + }; + window.muteErrors = () => { mute = true; } diff --git a/src/mono/sample/wasm/blazor-frame/wwwroot/index.html b/src/mono/sample/wasm/blazor-frame/wwwroot/index.html index dee342adfe4b03..a0855189943544 100644 --- a/src/mono/sample/wasm/blazor-frame/wwwroot/index.html +++ b/src/mono/sample/wasm/blazor-frame/wwwroot/index.html @@ -4,7 +4,7 @@ blazor - + @@ -26,7 +26,7 @@ Reload 🗙 - + diff --git a/src/mono/sample/wasm/browser-bench/AppStart.cs b/src/mono/sample/wasm/browser-bench/AppStart.cs index 5366bef2baeb6d..c6c26cb0f3792b 100644 --- a/src/mono/sample/wasm/browser-bench/AppStart.cs +++ b/src/mono/sample/wasm/browser-bench/AppStart.cs @@ -26,6 +26,7 @@ public AppStartTask() new ReachManagedCold(), new BlazorPageShow(), new BlazorReachManaged(), + new BlazorFirstUI(), new BlazorReachManagedCold(), }; } @@ -73,7 +74,7 @@ public override async Task RunStepAsync() abstract class BlazorAppStartMeasurement : BenchTask.Measurement { protected readonly string urlBase = "blazor-template/"; - protected readonly string framePage = "index.html"; + protected readonly string framePage = ""; public override async Task IsEnabled() { @@ -123,6 +124,18 @@ public override async Task RunStepAsync() } } + class BlazorFirstUI : BlazorAppStartMeasurement + { + public override string Name => "Blazor First UI"; + public override int InitialSamples => 3; + public override bool HasRunStepAsync => true; + + public override async Task RunStepAsync() + { + await MainApp.FrameBlazorFirstUI(null, urlBase); + } + } + class BlazorReachManagedCold : BlazorAppStartMeasurement { public override string Name => "Blazor Reach managed cold"; @@ -138,6 +151,8 @@ public override async Task RunStepAsync() public partial class MainApp { + [JSImport("globalThis.mainApp.FrameBlazorFirstUI")] + public static partial Task FrameBlazorFirstUI(string guid, string urlBase); [JSImport("globalThis.mainApp.PageShow")] public static partial Task PageShow(string guid, string urlBase); [JSImport("globalThis.mainApp.FrameReachedManaged")] diff --git a/src/mono/sample/wasm/browser-bench/main.js b/src/mono/sample/wasm/browser-bench/main.js index 894ea8d2e37fd6..846c9d693ef9a7 100644 --- a/src/mono/sample/wasm/browser-bench/main.js +++ b/src/mono/sample/wasm/browser-bench/main.js @@ -149,6 +149,14 @@ class MainApp { } } + async frameBlazorFirstUI(guid, base) { + try { + await this.waitFor('blazor: Rendered Index.razor', guid, base); + } finally { + this.removeFrame(); + } + } + framePage = 'appstart-frame.html'; async setFramePage(page) { @@ -187,6 +195,7 @@ class MainApp { try { globalThis.mainApp = new MainApp(); + globalThis.mainApp.FrameBlazorFirstUI = globalThis.mainApp.frameBlazorFirstUI.bind(globalThis.mainApp); globalThis.mainApp.FrameReachedManaged = globalThis.mainApp.frameReachedManaged.bind(globalThis.mainApp); globalThis.mainApp.PageShow = globalThis.mainApp.pageShow.bind(globalThis.mainApp); globalThis.mainApp.Origin = globalThis.mainApp.origin.bind(globalThis.mainApp); diff --git a/src/mono/sample/wasm/simple-server/HttpServer.csproj b/src/mono/sample/wasm/simple-server/HttpServer.csproj index 74abf5c9766499..330a025391578f 100644 --- a/src/mono/sample/wasm/simple-server/HttpServer.csproj +++ b/src/mono/sample/wasm/simple-server/HttpServer.csproj @@ -3,6 +3,7 @@ Exe net6.0 + major enable enable diff --git a/src/mono/sample/wasm/simple-server/Program.cs b/src/mono/sample/wasm/simple-server/Program.cs index 732403685a6c25..22de3d8ddabe04 100644 --- a/src/mono/sample/wasm/simple-server/Program.cs +++ b/src/mono/sample/wasm/simple-server/Program.cs @@ -177,7 +177,7 @@ private async void ServeAsync(HttpListenerContext context) if (url == null) return; - string path = url.LocalPath == "/" ? "index.html" : url.LocalPath; + string path = url.LocalPath.EndsWith("/") ? url.LocalPath + "index.html" : url.LocalPath; if (Verbose) Console.WriteLine($" serving: {path}");