From: Pavel Savara Date: Wed, 9 Aug 2023 01:07:41 +0000 (+0200) Subject: [browser] fix order of libraryInitializers execution (#90189) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~430 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=18b668ac2cbd4cd0c8ea40915854ed05069409eb;p=platform%2Fupstream%2Fdotnet%2Fruntime.git [browser] fix order of libraryInitializers execution (#90189) --- diff --git a/src/mono/sample/wasm/browser-advanced/main.js b/src/mono/sample/wasm/browser-advanced/main.js index 7b58f77..f95fcbf 100644 --- a/src/mono/sample/wasm/browser-advanced/main.js +++ b/src/mono/sample/wasm/browser-advanced/main.js @@ -30,6 +30,13 @@ try { // 'withModuleConfig' is internal lower level API // here we show how emscripten could be further configured // It is preferred to use specific 'with***' methods instead in all other cases. + .withConfig({ + resources: { + modulesAfterConfigLoaded: { + "advanced-sample.lib.module.js": "" + } + } + }) .withModuleConfig({ configSrc: "./blazor.boot.json", onConfigLoaded: (config) => { @@ -38,9 +45,6 @@ try { // config is loaded and could be tweaked before the rest of the runtime startup sequence config.environmentVariables["MONO_LOG_LEVEL"] = "debug"; config.browserProfilerOptions = {}; - config.resources.modulesAfterConfigLoaded = { - "advanced-sample.lib.module.js": "" - } }, preInit: () => { console.log('user code Module.preInit'); }, preRun: () => { console.log('user code Module.preRun'); }, diff --git a/src/mono/wasm/runtime/loader/config.ts b/src/mono/wasm/runtime/loader/config.ts index 053d769..dc7ba1e 100644 --- a/src/mono/wasm/runtime/loader/config.ts +++ b/src/mono/wasm/runtime/loader/config.ts @@ -228,6 +228,10 @@ export async function mono_wasm_load_config(module: DotnetModuleInternal): Promi normalizeConfig(); + // scripts need to be loaded before onConfigLoaded because Blazor calls `beforeStart` export in onConfigLoaded + await importLibraryInitializers(loaderHelpers.config.resources?.modulesAfterConfigLoaded); + await invokeLibraryInitializers("onRuntimeConfigLoaded", [loaderHelpers.config]); + if (module.onConfigLoaded) { try { await module.onConfigLoaded(loaderHelpers.config, exportedRuntimeAPI); @@ -239,8 +243,6 @@ export async function mono_wasm_load_config(module: DotnetModuleInternal): Promi } } - await importLibraryInitializers(loaderHelpers.config.resources?.modulesAfterConfigLoaded); - await invokeLibraryInitializers("onRuntimeConfigLoaded", [loaderHelpers.config]); normalizeConfig(); loaderHelpers.afterConfigLoaded.promise_control.resolve(loaderHelpers.config);