diff --git a/src/contexts/NotificationContext.js b/src/contexts/NotificationContext.js
index b8ccd63a..799fcf9d 100644
--- a/src/contexts/NotificationContext.js
+++ b/src/contexts/NotificationContext.js
@@ -49,39 +49,7 @@ export const NotificationProvider = ({ children }) => {
// ⚡ 移动端检测(使用 Redux 状态)
const isMobile = useSelector(selectIsMobile);
- // ⚡ 移动端禁用完整通知能力:返回空壳 Provider
- // 移动端不支持桌面通知,且不需要 Socket 实时推送
- if (isMobile) {
- const emptyValue = {
- notifications: [],
- isConnected: false,
- soundEnabled: false,
- browserPermission: 'default',
- connectionStatus: CONNECTION_STATUS.DISCONNECTED,
- reconnectAttempt: 0,
- maxReconnectAttempts: 0,
- addNotification: () => null,
- removeNotification: () => {},
- clearAllNotifications: () => {},
- toggleSound: () => {},
- requestBrowserPermission: () => Promise.resolve('default'),
- trackNotificationClick: () => {},
- retryConnection: () => {},
- showWelcomeGuide: () => {},
- showCommunityGuide: () => {},
- showFirstFollowGuide: () => {},
- registerEventUpdateCallback: () => () => {},
- unregisterEventUpdateCallback: () => {},
- };
-
- return (
-
- {children}
-
- );
- }
-
- // ========== 桌面端:完整通知功能 ==========
+ // ========== 所有 Hooks 必须在条件判断之前调用(React 规则) ==========
const toast = useToast();
const [notifications, setNotifications] = useState([]);
const [isConnected, setIsConnected] = useState(false);
@@ -1047,6 +1015,39 @@ export const NotificationProvider = ({ children }) => {
};
}, [browserPermission, toast]);
+ // ⚡ 移动端禁用完整通知能力:返回空壳 Provider
+ // 注意:此判断必须在所有 Hooks 之后(React 规则要求 Hooks 调用顺序一致)
+ if (isMobile) {
+ const emptyValue = {
+ notifications: [],
+ isConnected: false,
+ soundEnabled: false,
+ browserPermission: 'default',
+ connectionStatus: CONNECTION_STATUS.DISCONNECTED,
+ reconnectAttempt: 0,
+ maxReconnectAttempts: 0,
+ addNotification: () => null,
+ removeNotification: () => {},
+ clearAllNotifications: () => {},
+ toggleSound: () => {},
+ requestBrowserPermission: () => Promise.resolve('default'),
+ trackNotificationClick: () => {},
+ retryConnection: () => {},
+ showWelcomeGuide: () => {},
+ showCommunityGuide: () => {},
+ showFirstFollowGuide: () => {},
+ registerEventUpdateCallback: () => () => {},
+ unregisterEventUpdateCallback: () => {},
+ };
+
+ return (
+
+ {children}
+
+ );
+ }
+
+ // ========== 桌面端:完整通知功能 ==========
const value = {
notifications,
isConnected,