From 3d7b0045b7723315e9d4985784f9e81748731a03 Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Wed, 17 Dec 2025 16:34:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(NotificationContext):=20Mock=20=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E8=B7=B3=E8=BF=87=20Socket=20=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 REACT_APP_ENABLE_MOCK 环境变量检查 - Mock 模式下直接 return,避免连接生产服务器失败的错误 - 消除开发环境控制台的 WebSocket 连接错误 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/contexts/NotificationContext.js | 6 ++++++ 1 file changed, 6 insertions(+) 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 保护)');