From ed2cfbad362b8faf21d3f49bae1390cf6f2a8d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Sat, 12 Sep 2026 02:11:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=BF=E5=85=8D=E9=A2=84=E8=A7=88=E5=AE=B9?= =?UTF-8?q?=E5=99=A8=E5=8F=98=E5=8C=96=E9=87=8D=E7=BD=AE=E7=BC=A9=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 自动适配仅在图片或逻辑尺寸变化时执行 通过尺寸引用保留初始视口兜底值 --- .../components/preview/PreviewWorkspace.tsx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/PreviewWorkspace.tsx b/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/PreviewWorkspace.tsx index 62ce5f4d5..f9bfaa56d 100644 --- a/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/PreviewWorkspace.tsx +++ b/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/PreviewWorkspace.tsx @@ -55,6 +55,8 @@ export function PreviewWorkspace({ viewportRef.current, ); const [canvasSize, setCanvasSize] = useState({ width: 900, height: 640 }); + const canvasSizeRef = useRef(canvasSize); + canvasSizeRef.current = canvasSize; const [spaceHeld, setSpaceHeld] = useState(false); const [renderMode, setRenderMode] = useState('editor-overlay'); @@ -152,18 +154,12 @@ export function PreviewWorkspace({ height: logicalSize.height, }, canvasSize: { - width: element?.clientWidth || canvasSize.width, - height: element?.clientHeight || canvasSize.height, + width: element?.clientWidth || canvasSizeRef.current.width, + height: element?.clientHeight || canvasSizeRef.current.height, }, }), ); - }, [ - activeImageId, - canvasSize.height, - canvasSize.width, - logicalSize, - setViewport, - ]); + }, [activeImageId, logicalSize, setViewport]); const scaleViewportFromCenter = useCallback( (nextScale: number) => {