fix(editor): strip placement metadata on commit

This commit is contained in:
Aymeric Rabot
2026-06-08 02:12:01 -04:00
parent bd9e97e224
commit 73cd6e8614
3 changed files with 17 additions and 5 deletions
@@ -0,0 +1,10 @@
import { describe, expect, test } from 'bun:test'
import { stripTransient } from './placement-math'
describe('stripTransient', () => {
test('removes placement-only metadata flags before commit', () => {
expect(stripTransient({ isNew: true, isTransient: true, label: 'copy' })).toEqual({
label: 'copy',
})
})
})
@@ -111,13 +111,13 @@ export function isValidWallSideFace(normal: [number, number, number] | undefined
return Math.abs(normal[2]) > 0.7 return Math.abs(normal[2]) > 0.7
} }
/** /** Strip placement-only metadata flags before committing a draft. */
* Strip the `isTransient` flag from node metadata before committing.
*/
export function stripTransient(meta: any): any { export function stripTransient(meta: any): any {
if (!isObject(meta)) return meta if (!isObject(meta)) return meta
const { isTransient, ...rest } = meta as Record<string, any> const nextMeta = { ...(meta as Record<string, any>) }
return rest delete nextMeta.isNew
delete nextMeta.isTransient
return nextMeta
} }
const _up = new Vector3(0, 1, 0) const _up = new Vector3(0, 1, 0)
+2
View File
@@ -17,6 +17,7 @@ import {
EDITOR_LAYER, EDITOR_LAYER,
getSideFromNormal, getSideFromNormal,
isValidWallSideFace, isValidWallSideFace,
stripPlacementMetadataFlags,
triggerSFX, triggerSFX,
useEditor, useEditor,
} from '@pascal-app/editor' } from '@pascal-app/editor'
@@ -275,6 +276,7 @@ const MoveDoorTool: React.FC<{ node: DoorNode }> = ({ node: movingDoorNode }) =>
const cloned = structuredClone(movingDoorNode) as any const cloned = structuredClone(movingDoorNode) as any
delete cloned.id delete cloned.id
cloned.metadata = stripPlacementMetadataFlags(cloned.metadata)
const node = DoorNode.parse({ const node = DoorNode.parse({
...cloned, ...cloned,
position: [target.clampedX, target.clampedY, 0], position: [target.clampedX, target.clampedY, 0],