Skip to content

fix(wework): keep image previews loaded across session event updates - #2479

Merged
qdaxb merged 2 commits into
wecode-ai:mainfrom
qwertyerge:fix/wework-image-preview-loading-churn
Aug 7, 2026
Merged

qdaxb merged 2 commits into
wecode-ai:mainfrom
qwertyerge:fix/wework-image-preview-loading-churn

Conversation

@qwertyerge

@qwertyerge qwertyerge commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

问题

会话事件更新时,若当前 turn/run 中带有图片(用户消息附件、view_image/image_generation 生成的图片),图片预览会频繁回到 loading 占位状态,导致会话消息区域跳动。

根因

AttachmentImagePreview 的预览加载 effect 依赖 attachment 对象引用。会话事件流式更新会通过 turn 投影、block 更新、快照合并等路径重建消息/附件对象(内容相同、引用全新),每次都会触发 effect 重新执行,把 previewUrl 重置为 null 并回到 loading。

修复

  • 预览与灯箱加载 effect 改为以稳定内容标识(id + local_preview_url/local_path)为依赖,通过 ref 读取最新 attachment,避免对象引用变化导致重复加载;
  • 图片内容真正变化时标识仍会变化,加载逻辑照常重新触发。

验证

  • 新增回归单测:对象引用变化但内容相同 → 不重新加载、不回到 loading;内容标识变化 → 正常重置为 loading;
  • wework 全量单测通过(308 文件 / 2994 用例),eslint、prettier 干净;
  • 已用 ai:verify 在隔离的真实 Tauri 会话中启动确认工作台正常渲染。

Summary by CodeRabbit

  • Bug Fixes
    • Improved attachment image previews to consistently display the latest selected image.
    • Prevented stale attachment data from affecting preview loading and lightbox behavior.
    • Preserved already loaded previews for equivalent attachments, avoiding unnecessary reloads.
    • Fixed preview loading and refreshing when attachments share an ID but have different local files.
    • Improved lightbox navigation between attachments with distinct preview content.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9bcff6fc-2438-4c2e-875d-f4147b7b8948

📥 Commits

Reviewing files that changed from the base of the PR and between 4b88b58 and 7a17ce1.

📒 Files selected for processing (2)
  • wework/src/components/chat/AttachmentImagePreview.test.tsx
  • wework/src/components/chat/AttachmentImagePreview.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • wework/src/components/chat/AttachmentImagePreview.tsx

📝 Walkthrough

Walkthrough

AttachmentImagePreview now uses the current attachment ref and previewIdentity for asynchronous preview loading and lightbox navigation. Tests verify preview reuse, reloads after identity changes, and distinct previews for attachments with equal IDs but different paths.

Changes

Attachment preview lifecycle

Layer / File(s) Summary
Identity-safe preview loading
wework/src/components/chat/AttachmentImagePreview.tsx
The component derives identity from the attachment ID and preview path. It captures the current attachment for asynchronous loading and uses identity values for preview reuse and lightbox effects.
Attachment identity regression coverage
wework/src/components/chat/AttachmentImagePreview.test.tsx
Tests mock fetch, Tauri APIs, and object URLs. They verify reuse for equivalent attachments, reloads for changed identities, and lightbox navigation between distinct local paths.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving image previews during session event updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@wework/src/components/chat/AttachmentImagePreview.tsx`:
- Around line 285-287: Update reusablePreviewUrl in AttachmentImagePreview to
compare each attachment’s complete preview identity using local_preview_url ??
local_path, while retaining the ID comparison. Add a lightbox regression case in
AttachmentImagePreview.test.tsx covering equal IDs, different local_path values,
and absent local_preview_url.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 10501d12-84de-4a54-a1d2-8f5d6380b2eb

📥 Commits

Reviewing files that changed from the base of the PR and between b30058e and 4b88b58.

📒 Files selected for processing (2)
  • wework/src/components/chat/AttachmentImagePreview.test.tsx
  • wework/src/components/chat/AttachmentImagePreview.tsx

@qdaxb qdaxb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@qdaxb
qdaxb added this pull request to the merge queue Aug 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 7, 2026
@qdaxb
qdaxb added this pull request to the merge queue Aug 7, 2026
@qwertyerge
qwertyerge requested a review from qdaxb August 7, 2026 11:00
Merged via the queue into wecode-ai:main with commit 08dd1ac Aug 7, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants