fix(dns-viewer): parse empty to yaml error (#7616)

* feat(dns-viewer): initialize yamlContent with empty object string

* feat(dns-viewer): prevent overwriting user config with initial YAML values

* fix(dns-viewer): add null check for parsed yaml object
This commit is contained in:
oomeow
2026-07-29 00:53:38 +00:00
committed by GitHub
parent 3d8d7731e1
commit 382cbf9fb5
+3 -3
View File
@@ -246,10 +246,10 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
hosts: '',
})
// 用于YAML编辑模式
// 用于YAML编辑模式, 设置初始化值用于 updateValuesFromYaml 方法判断是否更新表格数据,避免覆盖用户自定义的配置
const [yamlContent, setYamlContent] = useReducer(
(_: string, next: string) => next,
'',
'{isInitValue: true}',
)
// 从配置对象更新表单值
@@ -428,7 +428,7 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
const updateValuesFromYaml = useCallback(() => {
try {
const parsedYaml = yaml.load(yamlContent) as any
if (!parsedYaml) return
if (!parsedYaml || parsedYaml['isInitValue']) return
skipYamlSyncRef.current = true
updateValuesFromConfig(parsedYaml)