fix: preserve tree default value when treeData starts empty (#7908)

When treeData is initially an empty array (e.g. before async data
arrives), updateTreeValue() would clear the modelValue because no
matching items could be found in the empty flattened data. This caused
default values to be lost.

Only call updateTreeValue() when flattenData has items, so that
modelValue is preserved until the actual tree data arrives.

Fixes #6522
master^2
Akuria 2026-05-16 10:41:42 +08:00 committed by GitHub
parent aac4e88353
commit ca5931e8c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
"@vben-core/shadcn-ui": patch
---
fix: preserve tree default value when treeData starts empty

View File

@ -70,7 +70,9 @@ let lastTreeData: any = null;
onMounted(() => {
watchEffect(() => {
flattenData.value = flatten(props.treeData, props.childrenField);
updateTreeValue();
if (flattenData.value.length > 0) {
updateTreeValue();
}
// treeData
const currentTreeData = JSON.stringify(props.treeData);