Skip to content

Commit d0528f6

Browse files
authored
Change the way we detect Node.js in SignalR JS/TS client. (#49066)
* Change the way we detect Node.js in SignalR JS/TS client.
1 parent 00fa5e1 commit d0528f6

File tree

1 file changed

+5
-5
lines changed
  • src/SignalR/clients/ts/signalr/src

1 file changed

+5
-5
lines changed

src/SignalR/clients/ts/signalr/src/Utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@ export class Arg {
3737
export class Platform {
3838
// react-native has a window but no document so we should check both
3939
public static get isBrowser(): boolean {
40-
return typeof window === "object" && typeof window.document === "object";
40+
return !Platform.isNode && typeof window === "object" && typeof window.document === "object";
4141
}
4242

4343
// WebWorkers don't have a window object so the isBrowser check would fail
4444
public static get isWebWorker(): boolean {
45-
return typeof self === "object" && "importScripts" in self;
45+
return !Platform.isNode && typeof self === "object" && "importScripts" in self;
4646
}
4747

4848
// react-native has a window but no document
4949
static get isReactNative(): boolean {
50-
return typeof window === "object" && typeof window.document === "undefined";
50+
return !Platform.isNode && typeof window === "object" && typeof window.document === "undefined";
5151
}
5252

5353
// Node apps shouldn't have a window object, but WebWorkers don't either
5454
// so we need to check for both WebWorker and window
5555
public static get isNode(): boolean {
56-
return !this.isBrowser && !this.isWebWorker && !this.isReactNative;
56+
return typeof process !== "undefined" && process.release && process.release.name === "node";
5757
}
5858
}
5959

@@ -295,4 +295,4 @@ export function getGlobalThis(): unknown {
295295
return global;
296296
}
297297
throw new Error("could not find global");
298-
}
298+
}

0 commit comments

Comments
 (0)