Skip to content

Commit

Permalink
fix(core): array field insert method crash in sparse array
Browse files Browse the repository at this point in the history
  • Loading branch information
dan0314 authored and dan0314 committed Oct 12, 2023
1 parent 8861ef5 commit 3915838
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/core/src/shared/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,32 @@ export const patchFieldStates = (
target: Record<string, GeneralField>,
patches: INodePatch<GeneralField>[]
) => {
const shouldClear: Record<string, boolean> = {}
patches.forEach(({ type, address, oldAddress, payload }) => {
if (type === 'remove') {
destroy(target, address, false)
} else if (type === 'update') {
if (payload) {
if(shouldClear[address]){
delete shouldClear[address]
}
target[address] = payload
if (target[oldAddress] === payload) {
target[oldAddress] = undefined
shouldClear[oldAddress] = true
}
}
if (address && payload) {
locateNode(payload, address)
}
}
})

Object.keys(shouldClear).forEach((key)=> {
if(target[key] === undefined){
delete target[key]
}
})
}

export const destroy = (
Expand Down

0 comments on commit 3915838

Please sign in to comment.