Skip to content
Open
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
23 changes: 2 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/Components/Web.JS/src/Boot.Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import { DotNet } from '@microsoft/dotnet-js-interop';
import { InitialRootComponentsList } from './Services/InitialRootComponentsList';
import { JSEventRegistry } from './Services/JSEventRegistry';

type BlazorServerStartOptions = Partial<CircuitStartOptions> & { circuit?: Partial<CircuitStartOptions> };

let started = false;

function boot(userOptions?: Partial<CircuitStartOptions>): Promise<void> {
function boot(userOptions?: BlazorServerStartOptions): Promise<void> {
if (started) {
throw new Error('Blazor has already started.');
}
started = true;

const configuredOptions = resolveOptions(userOptions);
// Accept the `circuit` property from the blazor.web.js options format
const normalizedOptions = userOptions?.circuit ?? userOptions;
const configuredOptions = resolveOptions(normalizedOptions);
setCircuitOptions(Promise.resolve(configuredOptions || {}));

JSEventRegistry.create(Blazor);
Expand Down
8 changes: 6 additions & 2 deletions src/Components/Web.JS/src/Boot.WebAssembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ import { InitialRootComponentsList } from './Services/InitialRootComponentsList'
import { JSEventRegistry } from './Services/JSEventRegistry';
import { printErr } from './Platform/Mono/MonoPlatform';

type BlazorWebAssemblyStartOptions = Partial<WebAssemblyStartOptions> & { webAssembly?: Partial<WebAssemblyStartOptions> };

let started = false;

async function boot(options?: Partial<WebAssemblyStartOptions>): Promise<void> {
async function boot(options?: BlazorWebAssemblyStartOptions): Promise<void> {
if (started) {
throw new Error('Blazor has already started.');
}
started = true;

setWebAssemblyOptions(Promise.resolve(options || {}));
// Accept the `webAssembly` property from the blazor.web.js options format
const normalizedOptions = options?.webAssembly ?? options ?? {};
setWebAssemblyOptions(Promise.resolve(normalizedOptions));

JSEventRegistry.create(Blazor);
const webAssemblyComponents = discoverComponents(document, 'webassembly') as WebAssemblyComponentDescriptor[];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using BasicTestApp;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using OpenQA.Selenium;
using TestServer;
using Xunit.Abstractions;

namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests;

public class ServerNestedOptionsTest : ServerTestBase<BasicTestAppServerSiteFixture<ServerStartup>>
{
public ServerNestedOptionsTest(
BrowserFixture browserFixture,
BasicTestAppServerSiteFixture<ServerStartup> serverFixture,
ITestOutputHelper output)
: base(browserFixture, serverFixture, output)
{
}

protected override void InitializeAsyncCore()
{
Navigate($"{ServerPathBase}/nestedCircuitOptions");
}

[Fact]
public void NestedCircuitOptionsAreAccepted()
{
var appElement = Browser.MountTestComponent<CounterComponent>();
var countDisplayElement = appElement.FindElement(By.TagName("p"));
Browser.Equal("Current count: 0", () => countDisplayElement.Text);

appElement.FindElement(By.TagName("button")).Click();
Browser.Equal("Current count: 1", () => countDisplayElement.Text);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using BasicTestApp;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using OpenQA.Selenium;
using Xunit.Abstractions;

namespace Microsoft.AspNetCore.Components.E2ETest.Tests;

public class WebAssemblyNestedOptionsTest : ServerTestBase<BlazorWasmTestAppFixture<BasicTestApp.Program>>
{
public WebAssemblyNestedOptionsTest(
BrowserFixture browserFixture,
BlazorWasmTestAppFixture<Program> serverFixture,
ITestOutputHelper output)
: base(browserFixture, serverFixture, output)
{
_serverFixture.PathBase = "/subdir";
}

protected override void InitializeAsyncCore()
{
base.InitializeAsyncCore();

// Navigate with query parameter to trigger nested options format
Navigate($"{ServerPathBase}?nested-options=true");
Browser.MountTestComponent<ConfigureRuntime>();
}

[Fact]
public void NestedWebAssemblyOptionsAreAccepted()
{
var element = Browser.Exists(By.Id("environment"));
Browser.Equal("true", () => element.Text);
}
}
24 changes: 19 additions & 5 deletions src/Components/test/testassets/BasicTestApp/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,25 @@
document.body.append(element);
}

Blazor.start({
configureRuntime: dotnet => {
dotnet.withEnvironmentVariable("CONFIGURE_RUNTIME", "true");
}
});
// Support both top-level and nested options format
// The nested format matches what blazor.web.js uses
const useNestedFormat = location.search.indexOf('nested-options=true') !== -1;

if (useNestedFormat) {
Blazor.start({
webAssembly: {
configureRuntime: dotnet => {
dotnet.withEnvironmentVariable("CONFIGURE_RUNTIME", "true");
}
}
});
} else {
Blazor.start({
configureRuntime: dotnet => {
dotnet.withEnvironmentVariable("CONFIGURE_RUNTIME", "true");
}
});
}
})();
</script>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@page "/nestedCircuitOptions"
@addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers"
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Basic test app - Nested Circuit Options</title>
<base href="~/" />
<link href="style.css" rel="stylesheet" />
<link rel="icon" href="data:,">
<component type="typeof(Microsoft.AspNetCore.Components.Web.HeadOutlet)" render-mode="Server" />
</head>
<body>
<root><component type="typeof(BasicTestApp.Index)" render-mode="Server" /></root>

<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="." class="reload">Reload</a>
<span class="dismiss">🗙</span>
</div>

<script src="_framework/blazor.server.js" autostart="false"></script>
<script>
Blazor.start({
circuit: {
reconnectionOptions: {
retryIntervalMilliseconds: Array.prototype.at.bind([5000, 5000, 5000, 10000, 30000]),
},
},
});
</script>
</body>
</html>
Loading