fix: prevent rules editor from clearing custom rules before load

This commit is contained in:
wonfen
2026-07-09 13:46:24 +08:00
parent 406c0ab5a7
commit 979defc070
2 changed files with 13 additions and 0 deletions
@@ -276,6 +276,7 @@ export const RulesEditorViewer = (props: Props) => {
const [prependSeq, setPrependSeq] = useState<string[]>([])
const [appendSeq, setAppendSeq] = useState<string[]>([])
const [deleteSeq, setDeleteSeq] = useState<string[]>([])
const hasLoadedSeqConfigRef = useRef(false)
const filteredPrependSeq = useMemo(
() => prependSeq.filter((rule) => match(rule)),
@@ -406,6 +407,7 @@ export const RulesEditorViewer = (props: Props) => {
}
}
const fetchContent = useCallback(async () => {
hasLoadedSeqConfigRef.current = false
const data = await readProfileFile(property)
const obj = yaml.load(data) as ISeqProfileConfig | null
@@ -415,6 +417,7 @@ export const RulesEditorViewer = (props: Props) => {
setPrevData(data)
setCurrData(data)
hasLoadedSeqConfigRef.current = true
}, [property])
useEffect(() => {
@@ -432,11 +435,19 @@ export const RulesEditorViewer = (props: Props) => {
// 优化:异步处理大数据yaml.dump,避免UI卡死
useEffect(() => {
if (!hasLoadedSeqConfigRef.current) {
return
}
if (!(prependSeq && appendSeq && deleteSeq)) {
return
}
const serialize = () => {
if (!hasLoadedSeqConfigRef.current) {
return
}
try {
setCurrData(
yaml.dump(