@@ -37,6 +37,7 @@ export enum ChannelStatus {
37
37
providedIn : 'root' ,
38
38
} )
39
39
export class Channel {
40
+ private _isHotReloading = false ;
40
41
private eventSource ! : SSE ;
41
42
private initParams ! : InitParams ;
42
43
private states ! : States ;
@@ -54,6 +55,10 @@ export class Channel {
54
55
return this . status ;
55
56
}
56
57
58
+ isHotReloading ( ) : boolean {
59
+ return this . _isHotReloading ;
60
+ }
61
+
57
62
getRootComponent ( ) : ComponentProto | undefined {
58
63
return this . rootComponent ;
59
64
}
@@ -83,6 +88,7 @@ export class Channel {
83
88
if ( data === '<stream_end>' ) {
84
89
this . eventSource . close ( ) ;
85
90
this . status = ChannelStatus . CLOSED ;
91
+ this . _isHotReloading = false ;
86
92
this . logger . log ( { type : 'StreamEnd' } ) ;
87
93
if ( this . queuedEvents . length ) {
88
94
const queuedEvent = this . queuedEvents . shift ( ) ! ;
@@ -162,6 +168,14 @@ export class Channel {
162
168
}
163
169
164
170
hotReload ( ) {
171
+ // Only hot reload if there's no request in-flight.
172
+ // Most likely the in-flight request will receive the updated UI.
173
+ // In the unlikely chance it doesn't, we will wait for the next
174
+ // hot reload trigger which is not ideal but acceptable.
175
+ if ( this . getStatus ( ) === ChannelStatus . OPEN ) {
176
+ return ;
177
+ }
178
+ this . _isHotReloading = true ;
165
179
const request = new UiRequest ( ) ;
166
180
const userEvent = new UserEvent ( ) ;
167
181
userEvent . setStates ( this . states ) ;
0 commit comments