JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix: language switch stuck loading
cycong_10da940f52eea
diff --git a/jiuwenswarm/channels/web/frontend/src/App.tsx b/jiuwenswarm/channels/web/frontend/src/App.tsxindex 4c6fe01177..7ee879e64b 100644--- a/jiuwenswarm/channels/web/frontend/src/App.tsx+++ b/jiuwenswarm/channels/web/frontend/src/App.tsx@@ -166,6 +166,7 @@ function storeSessionId(sessionId: string | null) {function AppContent() {const { t, i18n } = useTranslation();+ const tRef = useRef(t);// 优先使用存储的会话 ID,避免每次刷新创建新会话const [sessionId, setSessionId] = useState<string>(() => {const stored = getStoredSessionId();@@ -192,6 +193,11 @@ function AppContent() {const startupUpdateCheckRef = useRef(false);/** 从 SkillNet 等入口跳转配置页时,首次展开对应配置分组(如第三方服务) */const [configInitialExpandGroup, setConfigInitialExpandGroup] = useState<string | null>(null);++ useEffect(() => {+ tRef.current = t;+ }, [t]);+useEffect(() => {if (activeNav !== 'configpanel') {setConfigInitialExpandGroup(null);@@ -774,7 +780,7 @@ for (let i = payload.team.length; i < 10; i++) {addMessage({id: `history-restore-empty-${Date.now()}`,role: 'system',- content: t('sessions.restoreEmpty'),+ content: tRef.current('sessions.restoreEmpty'),timestamp: new Date().toISOString(),});}@@ -887,7 +893,7 @@ for (let i = payload.team.length; i < 10; i++) {addMessage({id: `history-load-failed-${Date.now()}`,role: 'system',- content: t('sessions.errors.restoreFailed', { sessionId }),+ content: tRef.current('sessions.errors.restoreFailed', { sessionId }),timestamp: new Date().toISOString(),});}@@ -898,7 +904,6 @@ for (let i = payload.team.length; i < 10; i++) {sessionId,historyBootstrapKey,request,- t,addMessage,addToolCall,addToolResult,diff --git a/jiuwenswarm/channels/web/frontend/src/features/historyRestore.ts b/jiuwenswarm/channels/web/frontend/src/features/historyRestore.tsindex a0a177f1f9..2c34cec014 100644--- a/jiuwenswarm/channels/web/frontend/src/features/historyRestore.ts+++ b/jiuwenswarm/channels/web/frontend/src/features/historyRestore.ts@@ -24,6 +24,8 @@ const ALLOWED_ASSISTANT_EVENT_TYPES = new Set([const HISTORY_RESTORE_DONE_CONTENT = 'done';/** 流式 chunk 之间的兜底:正常情况由 `done` / `page_complete` 等结束帧关闭;仅当缺少明确结束标记时使用 */const HISTORY_RESTORE_IDLE_MS = 500;+/** 首帧兜底:订阅已建立但后端未发任何 history.message 时,避免 UI 一直 loading */+const HISTORY_RESTORE_FIRST_FRAME_MS = 10_000;export interface HistoryToolReplayItem {kind: 'tool_call' | 'tool_result';@@ -483,6 +485,9 @@ export function beginHistoryRestore(options: BeginHistoryRestoreOptions): Historconst entries: HistoryTimelineEntry[] = [];let totalPages: number | null = null;let idleTimer: number | null = null;+ let firstFrameTimer: number | null = window.setTimeout(() => {+ finalize();+ }, HISTORY_RESTORE_FIRST_FRAME_MS);let disposed = false;const clearIdleTimer = () => {@@ -491,6 +496,12 @@ export function beginHistoryRestore(options: BeginHistoryRestoreOptions): HistoridleTimer = null;}};+ const clearFirstFrameTimer = () => {+ if (firstFrameTimer !== null) {+ window.clearTimeout(firstFrameTimer);+ firstFrameTimer = null;+ }+ };const unsubscribe = webClient.on(HISTORY_MESSAGE_EVENT, (event: WsEvent) => {if (disposed || generation !== restoreGeneration) {@@ -501,6 +512,7 @@ export function beginHistoryRestore(options: BeginHistoryRestoreOptions): Historif (!shouldProcessHistoryPayload(payload, options.sessionId)) {return;}+ clearFirstFrameTimer();if (typeof payload.total_pages === 'number' && Number.isFinite(payload.total_pages)) {totalPages = payload.total_pages;@@ -537,6 +549,7 @@ export function beginHistoryRestore(options: BeginHistoryRestoreOptions): Historif (disposed) return;disposed = true;clearIdleTimer();+ clearFirstFrameTimer();unsubscribe();if (activeRestore?.generation === generation) {activeRestore = null;@@ -653,6 +666,9 @@ export function fetchHistoryPage(options: FetchHistoryPageOptions): HistoryRestoconst entries: HistoryTimelineEntry[] = [];let totalPages: number | null = null;let idleTimer: number | null = null;+ let firstFrameTimer: number | null = window.setTimeout(() => {+ finalize();+ }, HISTORY_RESTORE_FIRST_FRAME_MS);let disposed = false;const clearIdleTimer = () => {@@ -661,6 +677,12 @@ export function fetchHistoryPage(options: FetchHistoryPageOptions): HistoryRestoidleTimer = null;}};+ const clearFirstFrameTimer = () => {+ if (firstFrameTimer !== null) {+ window.clearTimeout(firstFrameTimer);+ firstFrameTimer = null;+ }+ };const unsubscribe = webClient.on(HISTORY_MESSAGE_EVENT, (event: WsEvent) => {if (disposed || generation !== restoreGeneration) {@@ -671,6 +693,7 @@ export function fetchHistoryPage(options: FetchHistoryPageOptions): HistoryRestoif (!shouldProcessHistoryPayload(payload, options.sessionId, options.pageIdx)) {return;}+ clearFirstFrameTimer();if (typeof payload.total_pages === 'number' && Number.isFinite(payload.total_pages)) {totalPages = payload.total_pages;@@ -707,6 +730,7 @@ export function fetchHistoryPage(options: FetchHistoryPageOptions): HistoryRestoif (disposed) return;disposed = true;clearIdleTimer();+ clearFirstFrameTimer();unsubscribe();activePageFetchDispose = null;if (activeRestore?.generation === generation) {