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:
Jeff Emmett 2025-12-15 20:04:55 -05:00
parent 125ebacc00
commit a5e097f786
1 changed files with 6 additions and 12 deletions

View File

@ -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)