From da7ccebf664cd0190717be4e23fccbcbdc1bb8e5 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:58:49 +0800 Subject: [PATCH] perf(setting): defer layout dialog icon loading to first open Both settings sections mount the layout dialog, so its eager mount effect issued about eleven Tauri calls twice per settings-page visit before the dialog was ever opened. The icon scan now runs once, on the first open. --- Changelog.md | 3 +++ src/components/setting/mods/layout-viewer.tsx | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 51c123c80..32d329ea4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -28,6 +28,8 @@
🐞 修复问题 +- 修复「外部控制器」复制成功的提示一闪而过 +- 修复订阅的规则、代理组、节点编辑器快速连续操作时条目可能重复或错位 - 修复检测更新后又发布新版时,应用内更新失败 - 修复订阅响应过大导致内存占用过高,限制单次下载为 4 MiB - 修复全局模式默认停在 `DIRECT` 或 `REJECT` 导致流量未经代理,现自动切换到第一个策略组 @@ -63,6 +65,7 @@
🚀 优化改进 +- 优化设置页打开时的开销:布局设置弹窗首次打开时才加载图标 - 优化连接、规则和日志筛选:切换页面后保留过滤条件 - 优化全局模式代理列表:仅显示 `GLOBAL` 节点,选中其中的策略组时才显示该组 - 优化设置页开关和选项所在行的鼠标悬停高亮,便于对应说明与控件 diff --git a/src/components/setting/mods/layout-viewer.tsx b/src/components/setting/mods/layout-viewer.tsx index ed2799899..8536d67c0 100644 --- a/src/components/setting/mods/layout-viewer.tsx +++ b/src/components/setting/mods/layout-viewer.tsx @@ -14,7 +14,7 @@ import { convertFileSrc } from '@tauri-apps/api/core' import { join } from '@tauri-apps/api/path' import { open as openDialog } from '@tauri-apps/plugin-dialog' import { exists } from '@tauri-apps/plugin-fs' -import { forwardRef, useEffect, useState } from 'react' +import { forwardRef, useEffect, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { BaseDialog, DialogRef, Switch, TooltipIcon } from '@/components/base' @@ -62,9 +62,16 @@ export const LayoutViewer = forwardRef((_, ref) => { const { decorated, toggleDecorations } = useWindowDecorations() + // Icon paths are only reachable from the open dialog; both settings sections + // mount this viewer, so an eager read would double ~11 IPC calls per visit. + // Loaded once per mount, deferred to the first open. + const iconsLoadedRef = useRef(false) + useEffect(() => { + if (!open || iconsLoadedRef.current) return + iconsLoadedRef.current = true initIconPath() - }, []) + }, [open]) async function initIconPath() { const appDir = await getAppDir()