fix: prevent ValidationError by not setting undefined values in shape.meta
When unpinning a shape, the previous code set pinnedAtZoom, originalX, and originalY to undefined in shape.meta. This caused a ValidationError because tldraw requires JSON serializable values (undefined is not valid JSON). Fixed by using object destructuring to exclude these properties from meta instead of setting them to undefined. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
6e29384a79
commit
6f57c767f4
|
|
@ -175,17 +175,14 @@ export function usePinnedToView(
|
|||
} else {
|
||||
// Animation complete - clear pinned meta data
|
||||
try {
|
||||
// Create new meta without pinned properties (don't use undefined)
|
||||
const { pinnedAtZoom, originalX, originalY, ...cleanMeta } = (currentShape.meta || {}) as any
|
||||
editor.updateShape({
|
||||
id: shapeId as TLShapeId,
|
||||
type: currentShape.type,
|
||||
x: targetX,
|
||||
y: targetY,
|
||||
meta: {
|
||||
...currentShape.meta,
|
||||
pinnedAtZoom: undefined,
|
||||
originalX: undefined,
|
||||
originalY: undefined,
|
||||
},
|
||||
meta: cleanMeta,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error setting final position:', error)
|
||||
|
|
@ -198,17 +195,14 @@ export function usePinnedToView(
|
|||
} else {
|
||||
// Distance is too small, just set directly and clear meta
|
||||
try {
|
||||
// Create new meta without pinned properties (don't use undefined)
|
||||
const { pinnedAtZoom, originalX, originalY, ...cleanMeta } = (currentShape.meta || {}) as any
|
||||
editor.updateShape({
|
||||
id: shapeId as TLShapeId,
|
||||
type: currentShape.type,
|
||||
x: targetX,
|
||||
y: targetY,
|
||||
meta: {
|
||||
...currentShape.meta,
|
||||
pinnedAtZoom: undefined,
|
||||
originalX: undefined,
|
||||
originalY: undefined,
|
||||
},
|
||||
meta: cleanMeta,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error restoring original coordinates:', error)
|
||||
|
|
|
|||
Loading…
Reference in New Issue