fix(admin): keep group row keys stable while editing fields
The inline group/repeater renderer feeds vuedraggable an item key from a WeakMap, because rows loaded from the server carry no _id. updateRepeaterItem rebuilt every row with a fresh object spread on each keystroke, so the WeakMap missed and minted a brand new key, which remounted the whole row and dropped the input focus after a single character. Inherit the existing drag key onto the replacement row object so the key survives for the whole life of the row. Values that match no option still fall through to the previous coercion, so invalid input keeps reporting a precise error, and rows that already carry an _id continue to key off it. Covered by a new contract test that extracts the real repeaterDragKey and updateRepeaterItem from AksField.vue and drives them through a simulated typing session. Full suite: 661 tests passing.
This commit is contained in:
1 parent
064f4e0955
commit
0bc72616e5
2 files changed
+118
-1
No files matched your search
@@ -1212,7 +1212,16 @@ function removeRepeaterItem(index) {
|
||||
|
||||
function updateRepeaterItem(index, fieldKey, value) {
|
||||
const current = Array.isArray(props.modelValue) ? [...props.modelValue] : []
|
||||
current[index] = { ...current[index], [fieldKey]: value }
|
||||
const previous = current[index]
|
||||
const next = previous && typeof previous === 'object' ? { ...previous, [fieldKey]: value } : { [fieldKey]: value }
|
||||
// 行对象每次都被替换成新引用,WeakMap 认不出它就会生成新 key,整行随之
|
||||
// 重挂载、输入框失焦(表现为打一个字就退出编辑)。把旧 key 继承给新对象,
|
||||
// 行 key 在整行生命周期内保持稳定。
|
||||
const inheritedKey = previous && typeof previous === 'object' ? dragRowKeys.get(previous) : null
|
||||
if (inheritedKey) {
|
||||
dragRowKeys.set(next, inheritedKey)
|
||||
}
|
||||
current[index] = next
|
||||
emit('update:modelValue', current)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user