Skip to content

Commit 61984fd

Browse files
authored
[Blazor] Pass environment to runtime config only when defined (#62418)
1 parent 1f5e355 commit 61984fd

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ function prepareRuntimeConfig(options: Partial<WebAssemblyStartOptions>, onConfi
138138
const config: MonoConfig = {
139139
maxParallelDownloads: 1000000, // disable throttling parallel downloads
140140
enableDownloadRetry: false, // disable retry downloads
141-
applicationEnvironment: options.environment,
142141
};
143142

143+
if (options.environment) {
144+
config.applicationEnvironment = options.environment;
145+
}
146+
144147
const onConfigLoaded = async (loadedConfig: MonoConfig) => {
145148
if (!loadedConfig.environmentVariables) {
146149
loadedConfig.environmentVariables = {};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Globalization;
5+
using GlobalizationWasmApp;
6+
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
7+
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
8+
using Microsoft.AspNetCore.E2ETesting;
9+
using OpenQA.Selenium;
10+
using Xunit.Abstractions;
11+
12+
namespace Microsoft.AspNetCore.Components.E2ETest.Tests;
13+
14+
public class WebAssemblyEnvironmentTest : ServerTestBase<ToggleExecutionModeServerFixture<Program>>
15+
{
16+
public WebAssemblyEnvironmentTest(
17+
BrowserFixture browserFixture,
18+
ToggleExecutionModeServerFixture<Program> serverFixture,
19+
ITestOutputHelper output)
20+
: base(browserFixture, serverFixture, output)
21+
{
22+
}
23+
24+
[Fact]
25+
public void WebAssemblyEnvironment_Works()
26+
{
27+
Navigate($"{ServerPathBase}/");
28+
29+
// Verify that the environment gets detected as 'Staging'.
30+
Browser.Equal("Staging", () => Browser.FindElement(By.Id("environment")).Text);
31+
}
32+
}

src/Components/test/testassets/GlobalizationWasmApp/App.razor

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
<p>DateTime: <span id="dateTime">@(new DateTime(2020, 09, 02))</span></p>
77

88
<p>Localized string: <span id="localizedString">@Loc["Hello"]</span></p>
9+
10+
<WebAssemblyEnvironment />

src/Components/test/testassets/GlobalizationWasmApp/GlobalizationWasmApp.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
<!-- Resx generation on Resources.resx only -->
99
<GenerateResxSource>false</GenerateResxSource>
10+
11+
<WasmApplicationEnvironmentName>Staging</WasmApplicationEnvironmentName>
1012
</PropertyGroup>
1113

1214
<PropertyGroup Condition="'$(TestTrimmedOrMultithreadingApps)' == 'true'">
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@inject Microsoft.AspNetCore.Components.WebAssembly.Hosting.IWebAssemblyHostEnvironment HostEnvironment
2+
3+
<div id="environment">@HostEnvironment.Environment</div>

0 commit comments

Comments
 (0)