@@ -28,16 +28,17 @@ let connection: HubConnection;
28
28
let circuit : CircuitDescriptor ;
29
29
let dotNetDispatcher : CircuitDotNetCallDispatcher ;
30
30
let dispatcher : DotNet . ICallDispatcher ;
31
- let userOptions : Partial < CircuitStartOptions > | undefined ;
31
+ let renderQueue : RenderQueue ;
32
+ let options : CircuitStartOptions ;
32
33
let logger : ConsoleLogger ;
33
34
let afterRenderCallback : ( ( ) => void ) | undefined ;
34
35
35
36
export function setCircuitOptions ( circuitUserOptions ?: Partial < CircuitStartOptions > ) {
36
- if ( userOptions ) {
37
+ if ( options ) {
37
38
throw new Error ( 'Circuit options have already been configured.' ) ;
38
39
}
39
40
40
- userOptions = circuitUserOptions ;
41
+ options = resolveOptions ( circuitUserOptions ) ;
41
42
}
42
43
43
44
export async function startServer ( components : RootComponentManager < ServerComponentDescriptor > ) : Promise < void > {
@@ -48,7 +49,6 @@ export async function startServer(components: RootComponentManager<ServerCompone
48
49
started = true ;
49
50
50
51
// Establish options to be used
51
- const options = resolveOptions ( userOptions ) ;
52
52
logger = new ConsoleLogger ( options . logLevel ) ;
53
53
54
54
const jsInitializer = await fetchAndInvokeInitializers ( options ) ;
@@ -59,7 +59,7 @@ export async function startServer(components: RootComponentManager<ServerCompone
59
59
return false ;
60
60
}
61
61
62
- const reconnection = existingConnection || await initializeConnection ( options , logger , circuit ) ;
62
+ const reconnection = existingConnection || await initializeConnection ( logger , circuit ) ;
63
63
if ( ! ( await circuit . reconnect ( reconnection ) ) ) {
64
64
logger . log ( LogLevel . Information , 'Reconnection attempt to the circuit was rejected by the server. This may indicate that the associated state is no longer available on the server.' ) ;
65
65
return false ;
@@ -114,13 +114,13 @@ export function startCircuit(components: RootComponentManager<ServerComponentDes
114
114
}
115
115
116
116
startCircuitPromise ??= ( async ( ) => {
117
- const options = resolveOptions ( userOptions ) ;
118
117
const appState = discoverPersistedState ( document ) ;
118
+ renderQueue = new RenderQueue ( logger ) ;
119
119
circuit = new CircuitDescriptor ( components , appState || '' ) ;
120
120
dotNetDispatcher = new CircuitDotNetCallDispatcher ( ( ) => connection ) ;
121
121
dispatcher = DotNet . attachDispatcher ( dotNetDispatcher ) ;
122
122
123
- const initialConnection = await initializeConnection ( options , logger , circuit ) ;
123
+ const initialConnection = await initializeConnection ( logger , circuit ) ;
124
124
const circuitStarted = await circuit . startCircuit ( initialConnection ) ;
125
125
if ( ! circuitStarted ) {
126
126
logger . log ( LogLevel . Error , 'Failed to start the circuit.' ) ;
@@ -165,7 +165,7 @@ export function disposeCircuit() {
165
165
detachWebRendererInterop ( WebRendererId . Server ) ;
166
166
}
167
167
168
- async function initializeConnection ( options : CircuitStartOptions , logger : Logger , circuit : CircuitDescriptor ) : Promise < HubConnection > {
168
+ async function initializeConnection ( logger : Logger , circuit : CircuitDescriptor ) : Promise < HubConnection > {
169
169
const hubProtocol = new MessagePackHubProtocol ( ) ;
170
170
( hubProtocol as unknown as { name : string } ) . name = 'blazorpack' ;
171
171
@@ -196,7 +196,6 @@ async function initializeConnection(options: CircuitStartOptions, logger: Logger
196
196
dispatcher . supplyDotNetStream ( streamId , readableStream ) ;
197
197
} ) ;
198
198
199
- const renderQueue = new RenderQueue ( logger ) ;
200
199
newConnection . on ( 'JS.RenderBatch' , async ( batchId : number , batchData : Uint8Array ) => {
201
200
logger . log ( LogLevel . Debug , `Received render batch with id ${ batchId } and ${ batchData . byteLength } bytes.` ) ;
202
201
await renderQueue . processBatch ( batchId , batchData , newConnection ) ;
@@ -205,7 +204,7 @@ async function initializeConnection(options: CircuitStartOptions, logger: Logger
205
204
206
205
newConnection . on ( 'JS.EndLocationChanging' , Blazor . _internal . navigationManager . endLocationChanging ) ;
207
206
208
- newConnection . onclose ( error => ! renderingFailed && options . reconnectionHandler ! . onConnectionDown ( options . reconnectionOptions , error ) ) ;
207
+ newConnection . onclose ( error => isCircuitActive ( ) && ! renderingFailed && options . reconnectionHandler ! . onConnectionDown ( options . reconnectionOptions , error ) ) ;
209
208
newConnection . on ( 'JS.Error' , error => {
210
209
renderingFailed = true ;
211
210
unhandledError ( newConnection , error , logger ) ;
0 commit comments