File tree Expand file tree Collapse file tree 3 files changed +15
-10
lines changed
src/SignalR/clients/ts/signalr/src Expand file tree Collapse file tree 3 files changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -533,7 +533,7 @@ export class HttpConnection implements IConnection {
533
533
return url ;
534
534
}
535
535
536
- if ( ! Platform . isBrowser || ! window . document ) {
536
+ if ( ! Platform . isBrowser ) {
537
537
throw new Error ( `Cannot resolve '${ url } '.` ) ;
538
538
}
539
539
Original file line number Diff line number Diff line change @@ -180,10 +180,8 @@ export class HubConnection {
180
180
await this . _startInternal ( ) ;
181
181
182
182
if ( Platform . isBrowser ) {
183
- if ( document ) {
184
- // Log when the browser freezes the tab so users know why their connection unexpectedly stopped working
185
- document . addEventListener ( "freeze" , this . _freezeEventListener ) ;
186
- }
183
+ // Log when the browser freezes the tab so users know why their connection unexpectedly stopped working
184
+ window . document . addEventListener ( "freeze" , this . _freezeEventListener ) ;
187
185
}
188
186
189
187
this . _connectionState = HubConnectionState . Connected ;
@@ -734,9 +732,7 @@ export class HubConnection {
734
732
this . _connectionStarted = false ;
735
733
736
734
if ( Platform . isBrowser ) {
737
- if ( document ) {
738
- document . removeEventListener ( "freeze" , this . _freezeEventListener ) ;
739
- }
735
+ window . document . removeEventListener ( "freeze" , this . _freezeEventListener ) ;
740
736
}
741
737
742
738
try {
Original file line number Diff line number Diff line change @@ -35,16 +35,25 @@ export class Arg {
35
35
36
36
/** @private */
37
37
export class Platform {
38
+ // react-native has a window but no document so we should check both
38
39
public static get isBrowser ( ) : boolean {
39
- return typeof window === "object" ;
40
+ return typeof window === "object" && typeof window . document === "object" ;
40
41
}
41
42
43
+ // WebWorkers don't have a window object so the isBrowser check would fail
42
44
public static get isWebWorker ( ) : boolean {
43
45
return typeof self === "object" && "importScripts" in self ;
44
46
}
45
47
48
+ // react-native has a window but no document
49
+ static get isReactNative ( ) : boolean {
50
+ return typeof window === "object" && typeof window . document === "undefined" ;
51
+ }
52
+
53
+ // Node apps shouldn't have a window object, but WebWorkers don't either
54
+ // so we need to check for both WebWorker and window
46
55
public static get isNode ( ) : boolean {
47
- return ! this . isBrowser && ! this . isWebWorker ;
56
+ return ! this . isBrowser && ! this . isWebWorker && ! this . isReactNative ;
48
57
}
49
58
}
50
59
You can’t perform that action at this time.
0 commit comments