From 4abe6c1d9d98f01ea44a49a071f60ff559a228e0 Mon Sep 17 00:00:00 2001 From: Formsmith Date: Sat, 13 Jun 2026 09:01:18 +0300 Subject: [PATCH] Prevent project sync echo from rehydrating editor --- apps/web/src/components/SketchForgeEditor.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/apps/web/src/components/SketchForgeEditor.tsx b/apps/web/src/components/SketchForgeEditor.tsx index 6d98c7a..11aa7ad 100644 --- a/apps/web/src/components/SketchForgeEditor.tsx +++ b/apps/web/src/components/SketchForgeEditor.tsx @@ -4178,6 +4178,8 @@ export function SketchForgeEditor({ const pendingProjectShapesRef = useRef(null); const projectSyncTimerRef = useRef(null); const lastProjectShapesSyncRef = useRef(""); + const lastProjectShapesEchoRef = useRef(null); + const lastProjectIdRef = useRef(null); const projectSnapshotRunRef = useRef(0); const [projectInteractionActive, setProjectInteractionActive] = useState(false); @@ -4308,6 +4310,7 @@ export function SketchForgeEditor({ } projectSyncTimerRef.current = window.setTimeout(() => { lastProjectShapesSyncRef.current = serialized; + lastProjectShapesEchoRef.current = serialized; onProjectShapesChange({ projectId, shapes: canonicalNext }); projectSyncTimerRef.current = null; }, 120); @@ -4352,11 +4355,26 @@ export function SketchForgeEditor({ useEffect(() => { if (!projectId) { + lastProjectIdRef.current = null; lastProjectShapesSyncRef.current = ""; + lastProjectShapesEchoRef.current = null; return; } + if (lastProjectIdRef.current !== projectId) { + lastProjectIdRef.current = projectId; + lastProjectShapesSyncRef.current = ""; + lastProjectShapesEchoRef.current = null; + } const incoming = initialShapes.map(canonicalizeShape); const incomingSerialized = projectShapesFingerprint(incoming); + // The parent echoes shapes after a local save; rehydrating that echo can reset active transform state. + if (lastProjectShapesEchoRef.current !== null && incomingSerialized === lastProjectShapesEchoRef.current) { + lastProjectShapesSyncRef.current = incomingSerialized; + return; + } + if (projectInteractionActiveRef.current) { + return; + } lastProjectShapesSyncRef.current = incomingSerialized; if (projectSyncTimerRef.current !== null) { window.clearTimeout(projectSyncTimerRef.current);