mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 05:13:44 +08:00
perf: avoid reloading active config when editing inactive subscription
This commit is contained in:
parent
8d62c0d521
commit
bd3231bfa8
@ -35,6 +35,7 @@
|
||||
- 增加 IP 信息请求重试机制,减少 Network Error 发生的情况
|
||||
- 切换到规则页面时自动刷新规则数据
|
||||
- 重构更新失败回退机制,使用后端完成更新失败后回退到使用 Clash 代理再次尝试更新
|
||||
- 编辑非激活订阅的时候不在触发当前订阅配置重载
|
||||
|
||||
## v2.2.3
|
||||
|
||||
|
@ -22,9 +22,10 @@ import { createProfile, patchProfile } from "@/services/cmds";
|
||||
import { BaseDialog, Notice, Switch } from "@/components/base";
|
||||
import { version } from "@root/package.json";
|
||||
import { FileInput } from "./file-input";
|
||||
import { useProfiles } from "@/hooks/use-profiles";
|
||||
|
||||
interface Props {
|
||||
onChange: () => void;
|
||||
onChange: (isActivating?: boolean) => void;
|
||||
}
|
||||
|
||||
export interface ProfileViewerRef {
|
||||
@ -40,6 +41,7 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
||||
const [open, setOpen] = useState(false);
|
||||
const [openType, setOpenType] = useState<"new" | "edit">("new");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { profiles } = useProfiles();
|
||||
|
||||
// file input
|
||||
const fileDataRef = useRef<string | null>(null);
|
||||
@ -107,6 +109,10 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
||||
const name = form.name || `${form.type} file`;
|
||||
const item = { ...form, name };
|
||||
const isRemote = form.type === "remote";
|
||||
const isUpdate = openType === "edit";
|
||||
|
||||
// 判断是否是当前激活的配置
|
||||
const isActivating = isUpdate && form.uid === (profiles?.current ?? "");
|
||||
|
||||
// 保存原始代理设置以便回退成功后恢复
|
||||
const originalOptions = {
|
||||
@ -165,7 +171,9 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
||||
setOpen(false);
|
||||
setTimeout(() => formIns.reset(), 500);
|
||||
fileDataRef.current = null;
|
||||
props.onChange();
|
||||
|
||||
// 只传递当前配置激活状态,让父组件决定是否需要触发配置重载
|
||||
props.onChange(isActivating);
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString());
|
||||
} finally {
|
||||
|
@ -469,9 +469,12 @@ const ProfilePage = () => {
|
||||
|
||||
<ProfileViewer
|
||||
ref={viewerRef}
|
||||
onChange={async () => {
|
||||
onChange={async (isActivating) => {
|
||||
mutateProfiles();
|
||||
await onEnhance(false);
|
||||
// 只有更改当前激活的配置时才触发全局重新加载
|
||||
if (isActivating) {
|
||||
await onEnhance(false);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<ConfigViewer ref={configRef} />
|
||||
|
Loading…
x
Reference in New Issue
Block a user