Skip to content
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

[browser] Fix using startupOptions when loadBootResource is not specified #86371

Merged
merged 3 commits into from
May 17, 2023
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
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/loader/blazor/BootConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class BootConfigResult {
private constructor(public bootConfig: BootJsonData, public applicationEnvironment: string) {
}

static fromFetchResponse(bootConfigResponse: Response, bootConfig: BootJsonData, environment?: string): BootConfigResult {
static fromFetchResponse(bootConfigResponse: Response, bootConfig: BootJsonData, environment: string | undefined): BootConfigResult {
const applicationEnvironment = environment || (loaderHelpers.getApplicationEnvironment && loaderHelpers.getApplicationEnvironment(bootConfigResponse)) || "Production";
bootConfig.modifiableAssemblies = bootConfigResponse.headers.get("DOTNET-MODIFIABLE-ASSEMBLIES");
bootConfig.aspnetCoreBrowserTools = bootConfigResponse.headers.get("ASPNETCORE-BROWSER-TOOLS");
Expand Down
6 changes: 2 additions & 4 deletions src/mono/wasm/runtime/loader/blazor/_Integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import { ICUDataMode } from "../../types/blazor";
let resourceLoader: WebAssemblyResourceLoader;

export async function loadBootConfig(config: MonoConfigInternal, module: DotnetModuleInternal) {
const candidateOptions = config.startupOptions ?? {};
const environment = candidateOptions.environment;
const bootConfigPromise = BootConfigResult.initAsync(candidateOptions.loadBootResource, environment);
const bootConfigPromise = BootConfigResult.initAsync(config.startupOptions?.loadBootResource, config.applicationEnvironment);
const bootConfigResult: BootConfigResult = await bootConfigPromise;
await initializeBootConfig(bootConfigResult, module, candidateOptions);
await initializeBootConfig(bootConfigResult, module, config.startupOptions);
}

export async function initializeBootConfig(bootConfigResult: BootConfigResult, module: DotnetModuleInternal, startupOptions?: Partial<WebAssemblyStartOptions>) {
Expand Down
4 changes: 3 additions & 1 deletion src/mono/wasm/runtime/loader/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export async function mono_wasm_load_config(module: DotnetModuleInternal): Promi
}
if (loaderHelpers.diagnosticTracing) console.debug("MONO_WASM: mono_wasm_load_config");
try {
loaderHelpers.config.applicationEnvironment = loaderHelpers.config.applicationEnvironment ?? loaderHelpers.config.startupOptions?.environment ?? "Production";

if (loaderHelpers.config.startupOptions && loaderHelpers.config.startupOptions.loadBootResource) {
// If we have custom loadBootResource
await loadBootConfig(loaderHelpers.config, module);
Expand All @@ -91,7 +93,7 @@ export async function mono_wasm_load_config(module: DotnetModuleInternal): Promi
const loadedAnyConfig: any = (await configResponse.json()) || {};
if (loadedAnyConfig.resources) {
// If we found boot config schema
await initializeBootConfig(BootConfigResult.fromFetchResponse(configResponse, loadedAnyConfig as BootJsonData), module);
await initializeBootConfig(BootConfigResult.fromFetchResponse(configResponse, loadedAnyConfig as BootJsonData, loaderHelpers.config.applicationEnvironment), module, loaderHelpers.config.startupOptions);
} else {
// Otherwise we found mono config schema
const loadedConfig = loadedAnyConfig as MonoConfigInternal;
Expand Down