fix(chat): 修复图片查看器打开后视口测量时序回归导致的黑框 - #603
Open
AlphaCatMeow wants to merge 1 commit into
Open
Conversation
Stack-Cairn#448 迁移到 base-ui Dialog 后,viewport 仍用 useRef 在 open 变化时同步读取 DOM 节点,但 Dialog 内容此时尚未挂载,导致测量 effect 拿到 null 而无法设置 viewportSize,查看器打开后出现黑框且图片不渲染。 将 viewport 引用改为 callback ref + state,测量 effect 依赖 [open, viewportElement],在节点真正挂载后才触发测量;viewportRef 保留供 拖拽/滚轮锚点同步读取。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue
Closes #602
Summary
#448 将聊天图片查看器
ImagePreview的模态实现迁移到了@base-ui/react的Dialog组件,Dialog内容改为异步挂载。但视口测量逻辑仍然用useRef在open状态变化的同一个 effect 里同步读取视口 DOM 节点并测量尺寸——此时Dialog内容尚未真正挂载,viewportRef.current为null,viewportSize因此从未被正确设置,图片无法计算出正确渲染尺寸,表现为查看器打开后出现黑框、图片内容不渲染。修复方式:viewport 引用从纯
useRef改为 callback ref (setViewportRef) + state (viewportElement),测量 effect 依赖[open, viewportElement],在节点真正挂载后才会重新触发测量。viewportRef本身保留,供拖拽/滚轮锚点计算等其他逻辑继续同步读取。imagePreviewModel.ts纯函数层未改动。GUI 与 Gateway WebUI 共用同一份agent-ui组件,无需分别修复。Change scope
crates/agent-ui/src/components/chat/ImagePreview.tsxScreenshots / preview
修复后:图片查看器正常打开,无黑框,图片内容清晰渲染,工具栏(缩放、旋转、下载、信息面板、关闭等)完整可用。
Verification
pnpm agent-gui build: 通过pnpm agent-gui test:frontend: 通过pnpm agent-gateway/web build: 通过pnpm agent-gateway/web test: 通过check-ui-boundaries: 通过(既有 3 个不合规文件与本次改动无关,未新增)git diff --check: 通过,无空白错误start-tauri-dev.bat从本分支 HEAD 启动):已发送消息附件图片点击预览 ✅、composer 待发附件预览 ✅、缩放 ✅、旋转 ✅、拖拽 ✅、重置 ✅、全屏 ✅、信息面板 ✅。多图切换:确认该应用当前未提供切换上下张图片的按钮/交互(滚轮用于缩放),这是既有产品形态限制,非本次改动范围,不涉及回归Pre-submit checklist
Depends-On: none
Stack-Root: #603