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 {
|
} else {
|
||||||
// Animation complete - clear pinned meta data
|
// Animation complete - clear pinned meta data
|
||||||
try {
|
try {
|
||||||
|
// Create new meta without pinned properties (don't use undefined)
|
||||||
|
const { pinnedAtZoom, originalX, originalY, ...cleanMeta } = (currentShape.meta || {}) as any
|
||||||
editor.updateShape({
|
editor.updateShape({
|
||||||
id: shapeId as TLShapeId,
|
id: shapeId as TLShapeId,
|
||||||
type: currentShape.type,
|
type: currentShape.type,
|
||||||
x: targetX,
|
x: targetX,
|
||||||
y: targetY,
|
y: targetY,
|
||||||
meta: {
|
meta: cleanMeta,
|
||||||
...currentShape.meta,
|
|
||||||
pinnedAtZoom: undefined,
|
|
||||||
originalX: undefined,
|
|
||||||
originalY: undefined,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error setting final position:', error)
|
console.error('Error setting final position:', error)
|
||||||
|
|
@ -198,17 +195,14 @@ export function usePinnedToView(
|
||||||
} else {
|
} else {
|
||||||
// Distance is too small, just set directly and clear meta
|
// Distance is too small, just set directly and clear meta
|
||||||
try {
|
try {
|
||||||
|
// Create new meta without pinned properties (don't use undefined)
|
||||||
|
const { pinnedAtZoom, originalX, originalY, ...cleanMeta } = (currentShape.meta || {}) as any
|
||||||
editor.updateShape({
|
editor.updateShape({
|
||||||
id: shapeId as TLShapeId,
|
id: shapeId as TLShapeId,
|
||||||
type: currentShape.type,
|
type: currentShape.type,
|
||||||
x: targetX,
|
x: targetX,
|
||||||
y: targetY,
|
y: targetY,
|
||||||
meta: {
|
meta: cleanMeta,
|
||||||
...currentShape.meta,
|
|
||||||
pinnedAtZoom: undefined,
|
|
||||||
originalX: undefined,
|
|
||||||
originalY: undefined,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error restoring original coordinates:', error)
|
console.error('Error restoring original coordinates:', error)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue