Repository navigation
Conversation
「更多」下拉是 Semi Tooltip(trigger=click) 受控浮层:点击后 insertPortal 先离屏插入,jsdom 无布局且 ResizeObserver 是空桩,portalInserted 只能靠 100ms 安全网定时器触发,随后 calcPosition → positionUpdated → 可见,整条 链跨多个宏任务。原测试断言完即结束,链路常在卸载后才继续触发,偶发在 React/jsdom 内部抛 unhandled error(CI 记录 nodeType of null)判红整个文件。 aria-expanded 在 notifyVisibleChange 之后才翻成 true,是链路最末端信号; 等到它即保证挂起定时器全部在挂载状态下耗尽(实测 aria-expanded 翻 true 后 400ms 内 DOM 零 mutation)。不加测试重试、不跳过用例、不放宽断言。 验证:目标测试连跑 50 次全绿;typecheck/lint/全量 vitest(536 passed)/ playwright smoke 均通过。
supdger
added a commit
that referenced
this pull request
Nov 29, 2026
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.
根因
「更多」下拉是 Semi Tooltip(trigger=click) 的受控浮层。Semi 2.104.0 的显示链路是跨多个宏任务的异步链(已通过官方 @douyinfe/semi-mcp 核对 2.104.0 源码):
show()→insertPortal先把浮层离屏插入(isInsert=true,内容此刻已进 DOM);insertPortal等浮层尺寸稳定后才 emitportalInserted:优先 ResizeObserver + 32ms 稳定定时器,兜底是 100ms 安全网setTimeout(该定时器不存引用、不可取消);portalInserted→calcPosition→positionUpdated→togglePortalVisible(true)→notifyVisibleChange→ 受控visible翻转,链路才走完。测试环境 jsdom 无布局(offsetWidth 恒 0)且 setup 里的 ResizeObserver 是永不回调的空桩,所以这条链只能靠 100ms 安全网定时器推进。原测试断言(
findByText只依赖 DOM 存在性,插入后即满足)通常在几十毫秒内完成并结束,cleanup()卸载组件树后,挂起的安全网定时器及其后续链在卸载状态/半卸载状态下继续触发,偶发在 React/jsdom 内部抛出 unhandled error(CI 记录为Cannot read properties of null (reading 'nodeType')),vitest 将其判为整个测试文件失败——表现为偶发红、重跑即过(见 ci-tier-1117 / gates-sync-1117 的 RESULT 记录,push run 44183770429 命中过一次)。修改(只改测试文件)
web/src/pages/org/depts/DeptsPage.test.tsx:打开「更多」下拉、完成原有断言后,用waitFor等触发按钮的aria-expanded翻成true。该属性由 Dropdown 在notifyVisibleChange之后才更新,是整条异步链最末端的信号;等到它即保证所有挂起定时器都在挂载状态下耗尽。实测aria-expanded翻 true 后 400ms 内 DOM 零 mutation,无第二代定时器链。不加测试重试、不 skip/跳过用例、不放宽断言(反而多了一条断言)。
验证
npx vitest run src/pages/org/depts/DeptsPage.test.tsx连跑 50 次全绿(50/50,退出码全 0);pnpm typecheck:退出码 0;pnpm lint:退出码 0;pnpm test(全量 vitest):125 个文件、536 passed / 2 skipped,退出码 0;pnpm test:smoke(playwright,msw mock 起 dev server,无后端依赖):1 passed,退出码 0。基线:origin/main
5360129459241f4e0531fe3483f7c1f19119f7cd。