fix(preview): use static Message API to prevent addInstance crash in OfficeDocViewer#1781
fix(preview): use static Message API to prevent addInstance crash in OfficeDocViewer#1781
Conversation
…OfficeDocViewer Replace hook-based useMessage ref with static Message.error() in the loadDocument error handler. The hook-based API crashes when the context holder is not mounted (loading/error render paths omit it), causing TypeError: Cannot read properties of undefined (reading 'addInstance'). Add unit tests verifying static Message.error is called on conversion failure, error text is displayed, and successful conversion renders markdown. Fixes ELECTRON-AP
Code Review:fix(preview): use static Message API to prevent addInstance crash in OfficeDocViewer (#1781)变更概述本 PR 修复 方案评估结论:✅ 方案合理 根本原因定位准确: 问题清单🔵 LOW — 测试文件中存在未使用的
|
| # | 严重级别 | 文件 | 问题 |
|---|---|---|---|
| 1 | 🔵 LOW | tests/unit/OfficeDocViewer.dom.test.tsx:7 |
未使用的 act 导入 |
结论
act 导入),移除后即可合并。
CONCLUSION: CONDITIONAL
IS_CRITICAL_PATH: false
PR_NUMBER: 1781
本报告由本地 pr-review skill 生成,包含完整项目上下文,无截断限制。
PR Fix 验证报告原始 PR: #1781
总结: ✅ 已修复 0 个 | ⏭️ 已跳过 1 个(LOW)
|
Summary
useMessageref with staticMessage.error()in OfficeDocViewer'sloadDocumenterror handler to preventTypeError: Cannot read properties of undefined (reading 'addInstance')messageApiRef/useRefimport — the hook-based API only works whenmessageContextHolderis mounted, which is not the case during loading/error render pathsChanges
src/renderer/pages/conversation/Preview/components/viewers/OfficeDocViewer.tsxmessageApiRef(useRef) and its sync useEffectmessageApiRef.current?.error?.(errorMessage)withMessage.error(errorMessage)in the catch blockuseRefimporttests/unit/OfficeDocViewer.dom.test.tsx(new)Message.erroris called when conversion failsRelated Issue
Closes #1780
Sentry: ELECTRON-AP — 16 events, last seen 2026-03-26, affecting v1.9.1
Same root cause pattern as PR #1775 (
useMcpServerCRUD).Verification
bun run test -- --run tests/unit/OfficeDocViewer.dom.test.tsx)bunx tsc --noEmit)Test Plan
addInstanceTypeError in Sentry after deployment