fix: 解决window在构造函数中进行访问破坏SSR/Node环境。

master^2
layhuts 2026-05-09 12:33:15 +08:00
parent b40822e3ed
commit 0be4b51eaa
1 changed files with 6 additions and 0 deletions

View File

@ -17,6 +17,12 @@ class LocalStorageDriver implements IStorageDriver {
constructor({
storageType = 'localStorage',
}: LocalStorageDriverOptions = {}) {
if (typeof window === 'undefined') {
// eslint-disable-next-line unicorn/prefer-type-error -- not a type check, it's an environment check
throw new Error(
'LocalStorageDriver is not available in non-browser environments. Use MemoryStorageDriver instead.',
);
}
this.storage =
storageType === 'localStorage'
? window.localStorage