Skip to content

Commit

Permalink
fix(core): fix array child reactions invalid with remove (#3063)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Apr 21, 2022
1 parent 82cd80a commit 34e9420
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
13 changes: 12 additions & 1 deletion packages/core/src/__tests__/array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,20 @@ test('array field remove can not memory leak', async () => {
basePath: 'array.1',
})
)
const bb = attach(
form.createField({
name: 'bb',
basePath: 'array.1',
reactions: (field) => {
field.visible = field.query('.aa').value() === '123'
},
})
)
expect(bb.visible).toBeFalsy()
await array.remove(0)
form.query('array.0.aa').take((field) => {
;(field as DataField).value = '123'
})
expect(handler).toBeCalledTimes(2)
expect(bb.visible).toBeTruthy()
expect(handler).toBeCalledTimes(1)
})
10 changes: 5 additions & 5 deletions packages/core/src/shared/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ export const patchFieldStates = (
if (payload) {
target[address] = payload
if (target[oldAddress] === payload) {
target[oldAddress]?.dispose()
delete target[oldAddress]
}
}
Expand Down Expand Up @@ -387,10 +386,11 @@ export const spliceArrayState = (
if (number === undefined) return false
const index = Number(number)
return (
index >= startIndex &&
!fields[
`${preStr}${afterStr.replace(/^\.\d+/, `.${index + deleteCount}`)}`
]
(index > startIndex &&
!fields[
`${preStr}${afterStr.replace(/^\.\d+/, `.${index + deleteCount}`)}`
]) ||
index === startIndex
)
}
const moveIndex = (identifier: string) => {
Expand Down

0 comments on commit 34e9420

Please sign in to comment.