Skip to content

Commit 0e93f66

Browse files
committed
fix: enhance browser environment detection in InMemoryDriver to avoid false positives
1 parent ca8fe14 commit 0e93f66

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/plugins/driver-memory/src/memory-driver.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,9 +1082,13 @@ export class InMemoryDriver implements IDataDriver {
10821082

10831083
/**
10841084
* Detect whether the current runtime is a browser environment.
1085+
* Checks for window, document AND a functional localStorage to avoid
1086+
* false positives in Node.js runtimes that partially polyfill globals.
10851087
*/
10861088
private isBrowserEnvironment(): boolean {
1087-
return typeof globalThis.localStorage !== 'undefined';
1089+
return typeof globalThis.window !== 'undefined'
1090+
&& typeof globalThis.document !== 'undefined'
1091+
&& typeof globalThis.localStorage?.setItem === 'function';
10881092
}
10891093

10901094
/**

0 commit comments

Comments
 (0)