More misc sync fixes (#1559)

Follow-up to #1555, taking care of a few more rare edge cases found
during fuzz testing.

### Change Type

<!-- 💡 Indicate the type of change your pull request is. -->
<!-- 🤷‍♀️ If you're not sure, don't select anything -->
<!-- ✂️ Feel free to delete unselected options -->

<!-- To select one, put an x in the box: [x] -->

- [x] `patch` — Bug Fix
This commit is contained in:
David Sheldrick 2023-06-09 11:17:14 +01:00 committed by GitHub
parent 0cc91eec62
commit 707ddc876f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -1008,7 +1008,6 @@ export class Editor extends EventEmitter<TLEventMap> {
if (!withIndices) return EMPTY_ARRAY
return this._childIdsCache.get(withIndices, () => withIndices.map(([id]) => id))
}
/**
* Run a visitor function for all descendants of a shape.
*
@ -2134,7 +2133,8 @@ export class Editor extends EventEmitter<TLEventMap> {
return acc
}
const parent = this.store.get(parentId)!
const parent = this.store.get(parentId)
if (!parent) return acc
acc.push(parent)
return this.getAncestors(parent, acc)
}
@ -2152,7 +2152,8 @@ export class Editor extends EventEmitter<TLEventMap> {
* @public
*/
getAncestorsById(id: TLShapeId, acc: TLShape[] = []): TLShape[] {
const shape = this.getShapeById(id)!
const shape = this.getShapeById(id)
if (!shape) return acc
return this.getAncestors(shape, acc)
}
@ -4697,6 +4698,10 @@ export class Editor extends EventEmitter<TLEventMap> {
partial.y = point.y
partial.rotation = -this.getPageRotationById(parentId) + (partial.rotation ?? 0)
}
// a shape cannot be it's own parent. This was a rare issue with frames/groups in the syncFuzz tests.
if (partial.parentId === partial.id) {
partial.parentId = focusLayerId
}
return partial
}
return partial

View file

@ -50,7 +50,7 @@ export function getArrowTerminalInArrowSpace(
const boundShape = editor.getShapeById(terminal.boundShapeId)
if (!boundShape) {
console.error('Expected a bound shape!')
// this can happen in multiplayer contexts where the shape is being deleted
return new Vec2d(0, 0)
} else {
// Find the actual local point of the normalized terminal on