vue3 - 小程序 getCurrentInstance().value?.ctx.$children 始终存在销毁节点,导致其length不断增多
- Dominant language
- JavaScript
- Stars
- 41.6k
- Forks
- 3.7k
- Avg merge
- 7h 6m
- Merged PRs (30d)
- 6
Description
1.发生了什么
instance.value?.ctx.$children 始终存在销毁节点,导致其length不断增多
ex:
```vue
```
```vue
defineOptions({
name: "NhForm",
});
const instance = ref(null);
onMounted(() => {
instance.value = getCurrentInstance();
});
const nhFormRef = ref(null);
// const nhFormInstance = getCurrentInstance();
const validate = () => {
return new Promise((resolve, reject) => {
console.log(instance.value?.ctx.$parent.$children.length, 'nhFormRef')
if (!!instance.value?.ctx.$children.length) {
const hasInValid = instance.value?.ctx.$children.filter((item: any) => !item.validate());
resolve(!hasInValid.length);
} else {
resolve(true);
}
});
};
defineExpose({
validate,
});
```
通过 instance.value?.ctx.$children 获取 当前 slot 插槽渲染的组件,如果渲染组件时,内有条件组件,会导致这个 children.length 不断增加,比如当前实际3个节点,内部因条件事件导致出现了5个节点,销毁的节点也在。
期望:
instance.value?.ctx.$children 移除销毁节点;
```js
{
endMeasure(instance, `init`);
}
{
if (options.parentComponent && instance.proxy) {
// 具体源码问题出现在这里, 只有push,没有移除操作。
options.parentComponent.ctx.$children.push(getExposeProxy(instance) || instance.proxy);
}
}
setupRenderEffect(instance);
{
popWarningContext();
endMeasure(instance, `mount`);
}
```
Contributor guide
Assessment
This issue has not been assessed yet.