From f22477e9b7218a353b0fa55fa6560375fc2bafc8 Mon Sep 17 00:00:00 2001 From: rjf Date: Sun, 7 Dec 2025 16:55:53 +0100 Subject: [PATCH] fix of infinite loop browser/node detection --- src/utils.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 96d16d0..40aee87 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -125,12 +125,21 @@ export function keywordFilter(str: string, keywords: string[]): boolean { return true; } +// Precompute environment flags to avoid recursion when both globals exist (e.g. Electron renderer). +const hasWindow = typeof window !== "undefined"; +const hasProcess = typeof process !== "undefined"; +const hasElectron = hasProcess && !!(process as any).versions?.electron; + export function isBrowser(): boolean { - return typeof window !== 'undefined' && !isNode(); + return hasWindow && !hasElectron; } export function isNode(): boolean { - return typeof process !== 'undefined' && !isBrowser(); + return hasProcess && !hasElectron; +} + +export function isElectron(): boolean { + return hasElectron; } export function apiKeys() { @@ -180,4 +189,4 @@ export function join(...pathSegments: string[]): string { if (parts[0] === "") newParts.unshift(""); return newParts.join("/") || (newParts.length ? "/" : "."); -} \ No newline at end of file +}