-
Notifications
You must be signed in to change notification settings - Fork 10.4k
[Blazor] Flow the WebAssembly options from Server to client through SSR marker #60714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6284b44
Pass environment as SSR component payload for standalone mode
maraf 5a1040d
Read the environment in blazor.web
maraf dff3493
Find environment from all component descriptors
maraf 953e8b5
Emit a separate comment instead of extending component comment
maraf 014165a
TS clean up
maraf 2637fda
Pass DOTNET_MODIFIABLE_ASSEMBLIES & __ASPNETCORE_BROWSER_TOOLS in Web…
maraf b179835
Register the type in test
maraf ccf2fc9
Fix type registration in test
maraf df8d39e
Assert WebAssembly options in test
maraf c57e085
More web assembly test asserts
maraf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/Components/Endpoints/src/DependencyInjection/WebAssemblySettingsEmitter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Microsoft.AspNetCore.Components.Endpoints; | ||
|
||
internal record WebAssemblySettings(string EnvironmentName, Dictionary<string, string> EnvironmentVariables); | ||
|
||
internal class WebAssemblySettingsEmitter(IHostEnvironment hostEnvironment) | ||
{ | ||
private bool wasEmittedAlready; | ||
|
||
private const string dotnetModifiableAssembliesName = "DOTNET_MODIFIABLE_ASSEMBLIES"; | ||
private const string aspnetcoreBrowserToolsName = "__ASPNETCORE_BROWSER_TOOLS"; | ||
|
||
private static readonly string? s_dotnetModifiableAssemblies = GetNonEmptyEnvironmentVariableValue(dotnetModifiableAssembliesName); | ||
private static readonly string? s_aspnetcoreBrowserTools = GetNonEmptyEnvironmentVariableValue(aspnetcoreBrowserToolsName); | ||
|
||
private static string? GetNonEmptyEnvironmentVariableValue(string name) | ||
=> Environment.GetEnvironmentVariable(name) is { Length: > 0 } value ? value : null; | ||
|
||
public bool TryGetSettingsOnce([NotNullWhen(true)] out WebAssemblySettings? settings) | ||
{ | ||
if (wasEmittedAlready) | ||
{ | ||
settings = default; | ||
return false; | ||
} | ||
|
||
var environmentVariables = new Dictionary<string, string>(); | ||
|
||
// DOTNET_MODIFIABLE_ASSEMBLIES is used by the runtime to initialize hot-reload specific environment variables and is configured | ||
// by the launching process (dotnet-watch / Visual Studio). | ||
// Always add the header if the environment variable is set, regardless of the kind of environment. | ||
if (s_dotnetModifiableAssemblies != null) | ||
{ | ||
environmentVariables[dotnetModifiableAssembliesName] = s_dotnetModifiableAssemblies; | ||
} | ||
|
||
// See https://github.com/dotnet/aspnetcore/issues/37357#issuecomment-941237000 | ||
// Translate the _ASPNETCORE_BROWSER_TOOLS environment configured by the browser tools agent in to a HTTP response header. | ||
if (s_aspnetcoreBrowserTools != null) | ||
{ | ||
environmentVariables[aspnetcoreBrowserToolsName] = s_aspnetcoreBrowserTools; | ||
} | ||
|
||
wasEmittedAlready = true; | ||
settings = new (hostEnvironment.EnvironmentName, environmentVariables); | ||
return true; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.