From acf870ff6aff17ec4975983490cabb2d648e6c48 Mon Sep 17 00:00:00 2001 From: duckietm Date: Wed, 27 May 2026 07:46:10 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=86=99=20Enable=20back=20the=20live=20pre?= =?UTF-8?q?vies=20of=20the=20floorplan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rooms/widgets/useFloorplanLiveSync.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/hooks/rooms/widgets/useFloorplanLiveSync.ts b/src/hooks/rooms/widgets/useFloorplanLiveSync.ts index 8c5610c..ed3ae72 100644 --- a/src/hooks/rooms/widgets/useFloorplanLiveSync.ts +++ b/src/hooks/rooms/widgets/useFloorplanLiveSync.ts @@ -121,9 +121,8 @@ export const useFloorplanLiveSync = (opts: UseFloorplanLiveSyncOptions): UseFloo const baselineRef = useRef(null); const lastAppliedRef = useRef(null); + const wasEnabledRef = useRef(false); - // Destructure first so the memo deps stay precise without - // triggering exhaustive-deps on `state` as a whole. const { tiles, door, thickness, wallHeight } = state; const currentPayload = useMemo(() => ({ tilemap: serializeTilemap(tiles), @@ -150,18 +149,22 @@ export const useFloorplanLiveSync = (opts: UseFloorplanLiveSyncOptions): UseFloo if(applyToRenderer(baseline, roomId)) lastAppliedRef.current = baseline; }, [ roomId ]); - // Apply the current payload to the renderer whenever it - // diverges from what's already in the room. Synchronous + no - // debounce — the renderer pipeline is fast enough that every - // brush stroke can land a paint. useEffect(() => { - if(!enabled) return; + if(!enabled) + { + wasEnabledRef.current = false; + return; + } + + if(!baselineRef.current) return; + + const isFirstEnable = !wasEnabledRef.current; + wasEnabledRef.current = true; const previous = lastAppliedRef.current; - if(previous && livePreviewPayloadsEqual(currentPayload, previous)) return; - if(!previous && !baselineRef.current) return; + if(!isFirstEnable && previous && livePreviewPayloadsEqual(currentPayload, previous)) return; if(applyToRenderer(currentPayload, roomId)) lastAppliedRef.current = currentPayload; }, [ enabled, currentPayload, roomId ]);