@@ -14,11 +14,11 @@ import { BootConfigResult } from './Platform/BootConfig';
1414import { Pointer , System_Array , System_Boolean , System_Byte , System_Int , System_Object , System_String } from './Platform/Platform' ;
1515import { WebAssemblyStartOptions } from './Platform/WebAssemblyStartOptions' ;
1616import { WebAssemblyComponentAttacher } from './Platform/WebAssemblyComponentAttacher' ;
17- import { discoverComponents , discoverPersistedState , WebAssemblyComponentDescriptor } from './Services/ComponentDescriptorDiscovery' ;
17+ import { discoverPersistedState , WebAssemblyComponentDescriptor } from './Services/ComponentDescriptorDiscovery' ;
1818import { setDispatchEventMiddleware } from './Rendering/WebRendererInteropMethods' ;
1919import { fetchAndInvokeInitializers } from './JSInitializers/JSInitializers.WebAssembly' ;
2020
21- export async function startWebAssembly ( options ?: Partial < WebAssemblyStartOptions > ) : Promise < void > {
21+ export async function startWebAssembly ( options ?: Partial < WebAssemblyStartOptions > , components ?: WebAssemblyComponentDescriptor [ ] ) : Promise < void > {
2222 if ( inAuthRedirectIframe ( ) ) {
2323 // eslint-disable-next-line @typescript-eslint/no-empty-function
2424 await new Promise ( ( ) => { } ) ; // See inAuthRedirectIframe for explanation
@@ -90,18 +90,9 @@ export async function startWebAssembly(options?: Partial<WebAssemblyStartOptions
9090 Blazor . _internal . navigationManager . endLocationChanging ( callId , shouldContinueNavigation ) ;
9191 } ) ;
9292
93- const candidateOptions = options ?? { } ;
94-
95- // Get the custom environment setting and blazorBootJson loader if defined
96- const environment = candidateOptions . environment ;
97-
98- // Fetch the resources and prepare the Mono runtime
99- const bootConfigPromise = BootConfigResult . initAsync ( candidateOptions . loadBootResource , environment ) ;
100-
10193 // Leverage the time while we are loading boot.config.json from the network to discover any potentially registered component on
10294 // the document.
103- const discoveredComponents = discoverComponents ( document , 'webassembly' ) as WebAssemblyComponentDescriptor [ ] ;
104- const componentAttacher = new WebAssemblyComponentAttacher ( discoveredComponents ) ;
95+ const componentAttacher = new WebAssemblyComponentAttacher ( components || [ ] ) ;
10596 Blazor . _internal . registeredComponents = {
10697 getRegisteredComponentsCount : ( ) => componentAttacher . getCount ( ) ,
10798 getId : ( index ) => componentAttacher . getId ( index ) ,
@@ -122,13 +113,9 @@ export async function startWebAssembly(options?: Partial<WebAssemblyStartOptions
122113 }
123114 } ;
124115
125- const bootConfigResult : BootConfigResult = await bootConfigPromise ;
126- const jsInitializer = await fetchAndInvokeInitializers ( bootConfigResult . bootConfig , candidateOptions ) ;
127-
128- const [ resourceLoader ] = await Promise . all ( [
129- WebAssemblyResourceLoader . initAsync ( bootConfigResult . bootConfig , candidateOptions || { } ) ,
130- WebAssemblyConfigLoader . initAsync ( bootConfigResult ) ,
131- ] ) ;
116+ const bootConfigResult : BootConfigResult = await loadBootConfig ( options ) ;
117+ const jsInitializer = await fetchAndInvokeInitializers ( bootConfigResult . bootConfig , options ?? { } ) ;
118+ const resourceLoader = await beginLoadingDotNetRuntime ( options ?? { } , bootConfigResult ) ;
132119
133120 try {
134121 await platform . start ( resourceLoader ) ;
@@ -143,6 +130,25 @@ export async function startWebAssembly(options?: Partial<WebAssemblyStartOptions
143130 jsInitializer . invokeAfterStartedCallbacks ( Blazor ) ;
144131}
145132
133+ export async function loadBootConfig ( options ?: Partial < WebAssemblyStartOptions > ) {
134+ return BootConfigResult . initAsync ( options ?. loadBootResource , options ?. environment ) ;
135+ }
136+
137+ export async function beginLoadingDotNetRuntime ( options : Partial < WebAssemblyStartOptions > , bootConfigResult : BootConfigResult ) : Promise < WebAssemblyResourceLoader > {
138+ const candidateOptions = options ?? { } ;
139+
140+ // Get the custom environment setting and blazorBootJson loader if defined
141+ const environment = candidateOptions . environment ;
142+
143+ // Fetch the resources and prepare the Mono runtime
144+ const [ resourceLoader ] = await Promise . all ( [
145+ WebAssemblyResourceLoader . initAsync ( bootConfigResult . bootConfig , candidateOptions || { } ) ,
146+ WebAssemblyConfigLoader . initAsync ( bootConfigResult ) ,
147+ ] ) ;
148+
149+ return resourceLoader ;
150+ }
151+
146152// obsolete, legacy, don't use for new code!
147153function invokeJSFromDotNet ( callInfo : Pointer , arg0 : any , arg1 : any , arg2 : any ) : any {
148154 const functionIdentifier = monoPlatform . readStringField ( callInfo , 0 ) ! ;
0 commit comments