alibaba / formily

📱🚀 🧩 Cross Device & High Performance Normal Form/Dynamic(JSON Schema) Form/Form Builder -- Support React/React Native/Vue 2/Vue 3
https://formilyjs.org/
MIT License
11.47k stars 1.49k forks source link

[Bug Report] ArrayField.remove just replace the item with an "undefined", the length of the array not changed. #2128

Closed MisicDemone closed 3 years ago

MisicDemone commented 3 years ago

Reproduction link

Edit on CodeSandbox

Steps to reproduce

Just click "add" and "remove"

What is expected?

The length of array minus one.

What is actually happening?

The length of array not changed.

Package

@formily/core@2.0.0-rc.4


janryWang commented 3 years ago

该问题目前无解,因为Proxy拦截数组splice操作会把操作转换成离散的set操作,formily是无法感知到length改变的时候才触发,只会对第一次set操作触发,所以这就出现了length还没改变就触发的问题,主要也是因为需要支持同步触发模式,如果用户需要保证拿到准确的length,推荐自己加个setTimeout

Gllidan commented 2 months ago

该问题目前无解,因为Proxy拦截数组splice操作会把操作转换成离散的set操作,formily是无法感知到length改变的时候才触发,只会对第一次set操作触发,所以这就出现了length还没改变就触发的问题,主要也是因为需要支持同步触发模式,如果用户需要保证拿到准确的length,推荐自己加个setTimeout

为什么不考虑在form.makeReactive这一层做防抖呢?有什么场景是需要这个数据监测的实时性吗?