From fcff95496a8f6b870b49d7e49dc9c331cdca256f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 17 May 2023 09:31:05 +0200 Subject: [PATCH 1/3] Fix passing startupOptions to resourceLoader creation when loadBootResource is not specified --- src/mono/wasm/runtime/loader/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/runtime/loader/config.ts b/src/mono/wasm/runtime/loader/config.ts index 7e6b21ef4f6c31..c8fa0a5d606f6b 100644 --- a/src/mono/wasm/runtime/loader/config.ts +++ b/src/mono/wasm/runtime/loader/config.ts @@ -91,7 +91,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), module, loaderHelpers.config.startupOptions); } else { // Otherwise we found mono config schema const loadedConfig = loadedAnyConfig as MonoConfigInternal; From 310a3f1e70c7fca6d735936bbed8109714c2df1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 17 May 2023 11:03:51 +0200 Subject: [PATCH 2/3] Fix propagating applicationEnvironment --- src/mono/wasm/runtime/loader/blazor/BootConfig.ts | 2 +- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 11 +++++++---- src/mono/wasm/runtime/loader/config.ts | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/mono/wasm/runtime/loader/blazor/BootConfig.ts b/src/mono/wasm/runtime/loader/blazor/BootConfig.ts index 2dd751cbf748e4..05defc18901352 100644 --- a/src/mono/wasm/runtime/loader/blazor/BootConfig.ts +++ b/src/mono/wasm/runtime/loader/blazor/BootConfig.ts @@ -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"); diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index 22c0d65057836f..ab8c6f69551c78 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -14,11 +14,14 @@ 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 environment = getApplicationEnvironmentFromConfig(config); + const bootConfigPromise = BootConfigResult.initAsync(config.startupOptions?.loadBootResource, environment); const bootConfigResult: BootConfigResult = await bootConfigPromise; - await initializeBootConfig(bootConfigResult, module, candidateOptions); + await initializeBootConfig(bootConfigResult, module, config.startupOptions); +} + +export function getApplicationEnvironmentFromConfig(config: MonoConfigInternal): string | undefined { + return config.applicationEnvironment ?? config.startupOptions?.environment; } export async function initializeBootConfig(bootConfigResult: BootConfigResult, module: DotnetModuleInternal, startupOptions?: Partial) { diff --git a/src/mono/wasm/runtime/loader/config.ts b/src/mono/wasm/runtime/loader/config.ts index c8fa0a5d606f6b..859c551b513b2e 100644 --- a/src/mono/wasm/runtime/loader/config.ts +++ b/src/mono/wasm/runtime/loader/config.ts @@ -5,7 +5,7 @@ import BuildConfiguration from "consts:configuration"; import type { DotnetModuleInternal, MonoConfigInternal } from "../types/internal"; import type { DotnetModuleConfig } from "../types"; import { exportedRuntimeAPI, loaderHelpers, runtimeHelpers } from "./globals"; -import { initializeBootConfig, loadBootConfig } from "./blazor/_Integration"; +import { getApplicationEnvironmentFromConfig, initializeBootConfig, loadBootConfig } from "./blazor/_Integration"; import { BootConfigResult } from "./blazor/BootConfig"; import { BootJsonData } from "../types/blazor"; @@ -91,7 +91,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, loaderHelpers.config.startupOptions); + await initializeBootConfig(BootConfigResult.fromFetchResponse(configResponse, loadedAnyConfig as BootJsonData, getApplicationEnvironmentFromConfig(loaderHelpers.config)), module, loaderHelpers.config.startupOptions); } else { // Otherwise we found mono config schema const loadedConfig = loadedAnyConfig as MonoConfigInternal; From 889e045c250c37e7bfd359ec6ab3d547df95ab98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 17 May 2023 12:16:35 +0200 Subject: [PATCH 3/3] Different approach for applicationEnvironment --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 7 +------ src/mono/wasm/runtime/loader/config.ts | 6 ++++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index ab8c6f69551c78..47d9af0763be79 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -14,16 +14,11 @@ import { ICUDataMode } from "../../types/blazor"; let resourceLoader: WebAssemblyResourceLoader; export async function loadBootConfig(config: MonoConfigInternal, module: DotnetModuleInternal) { - const environment = getApplicationEnvironmentFromConfig(config); - const bootConfigPromise = BootConfigResult.initAsync(config.startupOptions?.loadBootResource, environment); + const bootConfigPromise = BootConfigResult.initAsync(config.startupOptions?.loadBootResource, config.applicationEnvironment); const bootConfigResult: BootConfigResult = await bootConfigPromise; await initializeBootConfig(bootConfigResult, module, config.startupOptions); } -export function getApplicationEnvironmentFromConfig(config: MonoConfigInternal): string | undefined { - return config.applicationEnvironment ?? config.startupOptions?.environment; -} - export async function initializeBootConfig(bootConfigResult: BootConfigResult, module: DotnetModuleInternal, startupOptions?: Partial) { INTERNAL.resourceLoader = resourceLoader = await WebAssemblyResourceLoader.initAsync(bootConfigResult.bootConfig, startupOptions ?? {}); mapBootConfigToMonoConfig(loaderHelpers.config, bootConfigResult.applicationEnvironment); diff --git a/src/mono/wasm/runtime/loader/config.ts b/src/mono/wasm/runtime/loader/config.ts index 859c551b513b2e..1d09292a0c9f15 100644 --- a/src/mono/wasm/runtime/loader/config.ts +++ b/src/mono/wasm/runtime/loader/config.ts @@ -5,7 +5,7 @@ import BuildConfiguration from "consts:configuration"; import type { DotnetModuleInternal, MonoConfigInternal } from "../types/internal"; import type { DotnetModuleConfig } from "../types"; import { exportedRuntimeAPI, loaderHelpers, runtimeHelpers } from "./globals"; -import { getApplicationEnvironmentFromConfig, initializeBootConfig, loadBootConfig } from "./blazor/_Integration"; +import { initializeBootConfig, loadBootConfig } from "./blazor/_Integration"; import { BootConfigResult } from "./blazor/BootConfig"; import { BootJsonData } from "../types/blazor"; @@ -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); @@ -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, getApplicationEnvironmentFromConfig(loaderHelpers.config)), module, loaderHelpers.config.startupOptions); + 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;