fix(ssr): avoid accessing window in EventBusDriver constructor during SSR
Build and Deploy / Build and Push Docker Image (push) Successful in 1m53s
Build and Deploy / Build and Push Docker Image (push) Successful in 1m53s
- Add window check in EventBusDriver constructor - Fix original-api.ts localStorage access - Prevent SSR hydration errors
This commit is contained in:
@@ -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) {
|
export function setActiveInterconnectNodeId(id: string, name?: string) {
|
||||||
activeInterconnectNodeId = id
|
activeInterconnectNodeId = id
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ class EventBusDriver {
|
|||||||
private initialized = false
|
private initialized = false
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
// 延迟初始化,避免 SSR 时访问 window
|
||||||
|
if (typeof window === 'undefined') return
|
||||||
|
|
||||||
const baseUrl = (window as any).__BASE_URL__ || ''
|
const baseUrl = (window as any).__BASE_URL__ || ''
|
||||||
const apiVersion = (window as any).__API_VERSION__ || '/api/v1'
|
const apiVersion = (window as any).__API_VERSION__ || '/api/v1'
|
||||||
let host = window.location.host
|
let host = window.location.host
|
||||||
|
|||||||
Reference in New Issue
Block a user