Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/mono/sample/wasm/blazor-frame/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
@page "/"
@inject IJSRuntime JSRuntime

<PageTitle>Index</PageTitle>

<h1>Hello, world!</h1>

Welcome to your new app.

@code {
protected override void OnAfterRender(bool firstRender)
{
BenchmarkEvent.Send(JSRuntime, "Rendered Index.razor");
}
}
7 changes: 7 additions & 0 deletions src/mono/sample/wasm/blazor-frame/wwwroot/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mono/sample/wasm/blazor-frame/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>blazor</title>
<!-- <base href="/blazor-template/" /> -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, what's the reason for this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Index.razor page wasn't loading properly, so I changed it according to https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/?view=aspnetcore-8.0&tabs=visual-studio#app-base-path

Interestingly I had to also change the blazor.webassembly.js path to make it work.

<base href="/blazor-template/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="css/bootstrap-icons/bootstrap-icons.min.css" />
<link rel="stylesheet" href="css/app.css" />
Expand All @@ -26,7 +26,7 @@
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="_framework/blazor.webassembly.js"></script>
<script src="/blazor-template/_framework/blazor.webassembly.js"></script>
<script type="module" src="frame.js"></script>
</body>

Expand Down
17 changes: 16 additions & 1 deletion src/mono/sample/wasm/browser-bench/AppStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public AppStartTask()
new ReachManagedCold(),
new BlazorPageShow(),
new BlazorReachManaged(),
new BlazorFirstUI(),
new BlazorReachManagedCold(),
};
}
Expand Down Expand Up @@ -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<bool> IsEnabled()
{
Expand Down Expand Up @@ -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";
Expand All @@ -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")]
Expand Down
9 changes: 9 additions & 0 deletions src/mono/sample/wasm/browser-bench/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/mono/sample/wasm/simple-server/HttpServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RollForward>major</RollForward>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/mono/sample/wasm/simple-server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");

Expand Down