fix: 修改 GlobalComponents.js(缓存 config)登录时不会触发 BytedeskWidget 重新加载

This commit is contained in:
zdl
2025-11-21 14:38:09 +08:00
parent e8b3d13c0a
commit 834067f679

View File

@@ -1,7 +1,7 @@
// src/components/GlobalComponents.js // src/components/GlobalComponents.js
// 集中管理应用的全局组件 // 集中管理应用的全局组件
import React from 'react'; import React, { useMemo } from 'react';
import { useLocation } from 'react-router-dom'; import { useLocation } from 'react-router-dom';
import { useNotification } from '../contexts/NotificationContext'; import { useNotification } from '../contexts/NotificationContext';
import { logger } from '../utils/logger'; import { logger } from '../utils/logger';
@@ -75,6 +75,9 @@ function ConnectionStatusBarWrapper() {
export function GlobalComponents() { export function GlobalComponents() {
const location = useLocation(); const location = useLocation();
// ✅ 缓存 Bytedesk 配置对象,避免每次渲染都创建新引用导致重新加载
const bytedeskConfigMemo = useMemo(() => getBytedeskConfig(), []);
return ( return (
<> <>
{/* Socket 连接状态条 */} {/* Socket 连接状态条 */}
@@ -89,9 +92,9 @@ export function GlobalComponents() {
{/* 通知容器 */} {/* 通知容器 */}
<NotificationContainer /> <NotificationContainer />
{/* Bytedesk在线客服 - 根据路径条件性显示 */} {/* Bytedesk在线客服 - 使用缓存的配置对象 */}
<BytedeskWidget <BytedeskWidget
config={getBytedeskConfig()} config={bytedeskConfigMemo}
autoLoad={true} autoLoad={true}
/> />
</> </>