@@ -59,6 +59,9 @@ function boot(options?: Partial<WebStartOptions>) : Promise<void> {
5959 enhancedNavigationStarted : ( ) => {
6060 jsEventRegistry . dispatchEvent ( 'enhancednavigationstart' , { } ) ;
6161 } ,
62+ documentReceived : ( source ) => {
63+ updateOptionsFromBrowserConfiguration ( options , source ) ;
64+ } ,
6265 documentUpdated : ( ) => {
6366 rootComponentManager . onDocumentUpdated ( ) ;
6467 resetScrollIfNeeded ( ScrollResetSchedule . AfterDocumentUpdate ) ;
@@ -99,8 +102,31 @@ function boot(options?: Partial<WebStartOptions>) : Promise<void> {
99102}
100103
101104function onInitialDomContentLoaded ( options : Partial < WebStartOptions > ) {
102- // Discover server-emitted browser configuration and merge into options
103- const browserConfig = discoverBrowserConfiguration ( document ) ;
105+ updateOptionsFromBrowserConfiguration ( options ) ;
106+
107+ // Retrieve and start invoking the initializers.
108+ // Blazor server options get defaults that are configured before we invoke the initializers
109+ // so we do the same here.
110+ const initialCircuitOptions = resolveOptions ( options ?. circuit || { } ) ;
111+ options . circuit = initialCircuitOptions ;
112+ options . webAssembly = options . webAssembly || ( { } as WebAssemblyStartOptions ) ;
113+ const logger = new ConsoleLogger ( initialCircuitOptions . logLevel ) ;
114+ const initializersPromise = fetchAndInvokeInitializers ( options , logger ) ;
115+ setCircuitOptions ( resolveConfiguredOptions ( initializersPromise , initialCircuitOptions ) ) ;
116+ setWebAssemblyOptions ( resolveConfiguredOptions ( initializersPromise , options . webAssembly ) ) ;
117+
118+ registerAllComponentDescriptors ( document ) ;
119+
120+ rootComponentManager . onDocumentUpdated ( ) ;
121+
122+ // Initialize client-side validation if the page has validatable fields.
123+ initFormValidationIfNeeded ( ) ;
124+
125+ callAfterStartedCallbacks ( initializersPromise ) ;
126+ }
127+
128+ function updateOptionsFromBrowserConfiguration ( options : Partial < WebStartOptions > , source : Document = document ) : void {
129+ const browserConfig = discoverBrowserConfiguration ( source ) ;
104130 if ( browserConfig ) {
105131 if ( browserConfig . logLevel !== undefined ) {
106132 options . logLevel = browserConfig . logLevel ;
@@ -141,37 +167,16 @@ function onInitialDomContentLoaded(options: Partial<WebStartOptions>) {
141167 }
142168 }
143169 }
144- }
145-
146- // Retrieve and start invoking the initializers.
147- // Blazor server options get defaults that are configured before we invoke the initializers
148- // so we do the same here.
149- const initialCircuitOptions = resolveOptions ( options ?. circuit || { } ) ;
150- options . circuit = initialCircuitOptions ;
151- options . webAssembly = options . webAssembly || ( { } as WebAssemblyStartOptions ) ;
152- const logger = new ConsoleLogger ( initialCircuitOptions . logLevel ) ;
153- const initializersPromise = fetchAndInvokeInitializers ( options , logger ) ;
154- setCircuitOptions ( resolveConfiguredOptions ( initializersPromise , initialCircuitOptions ) ) ;
155- setWebAssemblyOptions ( resolveConfiguredOptions ( initializersPromise , options . webAssembly ) ) ;
156170
157- // If BrowserConfiguration had WebAssembly server options, apply them
158- // before registering component descriptors, since registration triggers
159- // WebAssembly platform loading which captures these options.
160- if ( browserConfig ?. webAssembly ) {
161- rootComponentManager . setWebAssemblyOptions ( {
162- environmentName : browserConfig . webAssembly . environmentName ?? '' ,
163- environmentVariables : browserConfig . webAssembly . environmentVariables ?? { } ,
164- } ) ;
171+ // Apply WebAssembly server options before processing component descriptors, since
172+ // registration can trigger platform loading that captures these options.
173+ if ( browserConfig . webAssembly ) {
174+ rootComponentManager . setWebAssemblyOptions ( {
175+ environmentName : browserConfig . webAssembly . environmentName ?? '' ,
176+ environmentVariables : browserConfig . webAssembly . environmentVariables ?? { } ,
177+ } ) ;
178+ }
165179 }
166-
167- registerAllComponentDescriptors ( document ) ;
168-
169- rootComponentManager . onDocumentUpdated ( ) ;
170-
171- // Initialize client-side validation if the page has validatable fields.
172- initFormValidationIfNeeded ( ) ;
173-
174- callAfterStartedCallbacks ( initializersPromise ) ;
175180}
176181
177182function initFormValidationIfNeeded ( ) : void {
0 commit comments