Compact children when updating parents to children. (#2072)
This PR fixes (or rather buries) a bug that could occur when the parents to children array includes shapes that no longer exist. ### Change Type - [x] `patch` — Bug fix
This commit is contained in:
parent
bfb61b12ad
commit
1f4df14d4f
1 changed files with 3 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
import { computed, isUninitialized, RESET_VALUE } from '@tldraw/state'
|
||||
import { RecordsDiff } from '@tldraw/store'
|
||||
import { isShape, TLParentId, TLRecord, TLShape, TLShapeId, TLStore } from '@tldraw/tlschema'
|
||||
import { compact } from '@tldraw/utils'
|
||||
import { sortByIndex } from '../../utils/reordering/reordering'
|
||||
|
||||
type Parents2Children = Record<TLParentId, TLShapeId[]>
|
||||
|
@ -102,7 +103,8 @@ export const parentsToChildren = (store: TLStore) => {
|
|||
|
||||
// Sort the arrays that have been marked for sorting
|
||||
for (const arr of toSort) {
|
||||
const shapesInArr = arr.map((id) => store.get(id)!)
|
||||
// It's possible that some of the shapes may be deleted. But in which case would this be so?
|
||||
const shapesInArr = compact(arr.map((id) => store.get(id)))
|
||||
shapesInArr.sort(sortByIndex)
|
||||
arr.splice(0, arr.length, ...shapesInArr.map((shape) => shape.id))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue