diff --git a/src/contexts/NotificationContext.js b/src/contexts/NotificationContext.js index 0ab4a93b..757e5d8f 100644 --- a/src/contexts/NotificationContext.js +++ b/src/contexts/NotificationContext.js @@ -661,6 +661,12 @@ export const NotificationProvider = ({ children }) => { // ========== 连接到 Socket 服务(⚡ 异步初始化,不阻塞首屏) ========== useEffect(() => { + // ⚡ Mock 模式下跳过 Socket 连接(避免连接生产服务器失败的错误) + if (process.env.REACT_APP_ENABLE_MOCK === 'true') { + logger.debug('NotificationContext', 'Mock 模式,跳过 Socket 连接'); + return; + } + // ⚡ 防止 React Strict Mode 导致的重复初始化 if (socketInitialized) { logger.debug('NotificationContext', 'Socket 已初始化,跳过重复执行(Strict Mode 保护)');