diff --git a/web/src/api/original-api.ts b/web/src/api/original-api.ts index e5f9ebc..ade02e9 100644 --- a/web/src/api/original-api.ts +++ b/web/src/api/original-api.ts @@ -65,8 +65,16 @@ export interface MonitorStats { }[] } } -export let activeInterconnectNodeId = localStorage.getItem('activeInterconnectNodeId') || '' -export let activeInterconnectNodeName = localStorage.getItem('activeInterconnectNodeName') || '' + +// 初始化时使用空字符串,避免 SSR 时访问 localStorage +export let activeInterconnectNodeId = '' +export let activeInterconnectNodeName = '' + +// 在客户端初始化时从 localStorage 读取 +if (typeof window !== 'undefined') { + activeInterconnectNodeId = localStorage.getItem('activeInterconnectNodeId') || '' + activeInterconnectNodeName = localStorage.getItem('activeInterconnectNodeName') || '' +} export function setActiveInterconnectNodeId(id: string, name?: string) { activeInterconnectNodeId = id diff --git a/web/src/lib/event-bus.ts b/web/src/lib/event-bus.ts index ca53218..deb1d91 100644 --- a/web/src/lib/event-bus.ts +++ b/web/src/lib/event-bus.ts @@ -21,6 +21,9 @@ class EventBusDriver { private initialized = false constructor() { + // 延迟初始化,避免 SSR 时访问 window + if (typeof window === 'undefined') return + const baseUrl = (window as any).__BASE_URL__ || '' const apiVersion = (window as any).__API_VERSION__ || '/api/v1' let host = window.location.host