Skip to content

fix(ui): 卸载流式 Markdown 测试根节点并防护定时器回调 - #323

Merged
helsome merged 1 commit into
helsome:mainfrom
xuilen:fix/streaming-markdown-timer-leak
Oct 18, 2026
Merged

helsome merged 1 commit into
helsome:mainfrom
xuilen:fix/streaming-markdown-timer-leak

Conversation

@xuilen

@xuilen xuilen commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

fix(ui): 卸载流式 Markdown 测试根节点并防护定时器回调

改了什么

  1. 在 packages/ui/src/components/chat/MarkdownContent.test.tsx 的流式测试用例结束前,显式调用 act(() => { streamingRoot.unmount(); staticRoot.unmount(); })。
  2. 在 packages/ui/src/components/chat/MarkdownContent.tsx 中 useStreamingContent 内部定时器回调触发 setDisplayContent 前增加 typeof window !== 'undefined' 防御性判断。

为什么要改

在 PR #285 引入的 keeps partial blocks stable and matches static rendering when complete 测试中,组件以 streaming={true} 挂载并触发了 setTimeout(..., 16) 帧合并调度器。由于测试未卸载该 root,在测试完成、afterAll 中的 restoreDom() 销毁 window 之后,残留于 Node/Bun 事件循环的定时器延迟触发并执行 setDisplayContent,在无 window 状态下访问 window.event 抛出 ReferenceError: window is not defined,导致后置测试(如 SourceInspector.test.tsx)被污染报错并导致 UI 测试套件整体 Exit 1。

对应 Issue

无直接对应 Issue(在本地运行全量 CI / focused-tests 时发现的深层测试泄漏与异常)。

做了哪些验证

测试环境:Windows 11 / Bun 1.4.2 / Node v24.20.0

  1. 聚焦复现验证:

    • 修复前:bun test packages/ui/src/components/chat/MarkdownContent.test.tsx packages/ui/src/components/chat/SourceInspector.test.tsx
      → 6 pass / 1 fail / 2 errors(ReferenceError: window is not defined)
    • 修复后:同一命令 → 14 pass / 0 fail
  2. 工作区测试(Focused tests):

    • bun test packages/ui
    • 修复前:327 pass / 1 fail / 2 errors(Exit 1)
    • 修复后:335 pass / 0 fail,1129 expect() calls(Exit 0)
  3. 全仓测试(Full unit suite):

    • bun test --isolate
    • 结果:1776 pass / 8 skip / 0 fail(8 项 skip 均为 real CLI fixture 与 Windows 非开发者模式 symlink 基线差异)
  4. 类型检查:

    • bun run typecheck
    • 结果:@finagent/core, @finagent/i18n, @finagent/shared, @finagent/ui, @finagent/electron 全部 Exit 0
  5. 高危信息扫描:

    • 确认无任何 API Key、Token 或密钥提交。

UI 变化与截图

无可见 UI 变化(纯内部测试和时钟卸载保护)。

@helsome helsome left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

独立审查通过。本轮精确 HEAD focused tests 14 pass / 0 fail、类型检查通过;按当前顺序累计组合完整测试 1817 pass / 7 skip / 0 fail,全 typecheck 与 i18n 通过。生产变更文件高信号 secret 扫描无命中(非完整历史扫描)。本 PR 按明确范围验收,不替代父 Issue 未完成的真实模型/UI/其他范围验收。

@helsome
helsome merged commit 31b91a7 into helsome:main Oct 18, 2026
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