Repository navigation
fix(diagnostic): fail() 的红条改为按 phase 单实例,可关闭、可在 dispose 时清理(#767) - #824
Open
yanzhaohui1999 wants to merge 3 commits into
Open
yanzhaohui1999 wants to merge 3 commits into
yanzhaohui1999 wants to merge 3 commits into
Conversation
两处冲突 + 一处 git 看不见的语义冲突: 1) `tests/e2e/mount.e2e.ts` 与 `tests/e2e/native-reload.e2e.ts` 的 import 行:上游给 `./host` 增加了 `dismissOnboarding`(新的引导浮层会挡住点击),本分支增加了 `diagnostic-strip.ts` 的地址契约常量。两边都要,合并成一行 `./host` 导入 + 一条契约 常量导入(上游在这两个 spec 里对 `dismissOnboarding` 的调用点在别的 hunk,已自动合入)。 2) **`src/client/index.tsx` 的 `diagnostics` 重名**——git 自动合过,typecheck 才发现: 上游的 dsh-context 集成有自己的 `const diagnostics = createContextDiagnosticsHost(ctx)`, 本分支又把 `fail()` 的浮条绑成 `const diagnostics = createDiagnosticStrips()`。两处都 在同一个函数体里,且类型不同(`ContextDiagnostics` vs `DiagnosticStrips`)。上游的那个 改名 `contextDiagnostics`(它自己的四处消费点一并改),本分支保留 `diagnostics`。 门禁:typecheck 干净;全量 vitest 2688 passed / 17 skipped / 1 failed(唯一红是既有的 smoke 写 `$HOME` 被本机沙箱 EPERM 拒);挂载 lane 单独跑(两个被改的 spec 正是它的内容)。
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.
问题
fail()(src/client/index.tsx)是插件的 last-resort 上报器:除了console.error,它还会往document.body追加一条固定定位的红条,而全仓没有任何移除路径——bar没有 id / class(外部只能靠内联样式里的2147483000魔数定位),没有bar.remove(),也不在 fiber cleanup 里清理。它有 5 个调用点(
mount/interception/ime guard/load/native …),任一处反复失败就叠一条:每条的内联样式逐字相同(同一个
position:fixed;left:8px;bottom:8px),所以它们在视觉上完全重叠——用户只读得到最后追加的那条,而 DOM 里越积越多(issue 给的 DevTools 计数
document.querySelectorAll('div[style*="2147483000"]').length就是 1 → 2 → 3),最早那条失败信息再也读不到,且没有任何移除路径(只能刷新页面)。
#822(merge train)又给sync()的 reject 接了两个fail('sync', …)调用点(其中之一挂在settings/document-updated广播上),症状只会更频繁。修复
新增
src/client/diagnostic-strip.ts,把红条的 DOM 与生命周期独立成模块:dsh-better-sidebar-diagnostic):一次失败不再新增元素;fail()上报的每一行带data-dsh-better-sidebar-diagnostic-phase,e2e 与用户侧脚本不必再猜 z-index 魔数。clear()+ctx.effectdisposer:fiber 释放(HMR / 插件禁用)时整条 strip 连它占的 DOM 一起收走;新激活attach()前会先移除上一激活遗留的同 id host,所以页面不会同时存在两条 strip。--dsw-alias-*token 链(尾值为旧硬编码 hex),皮肤契约不变;模块刻意零依赖、不用 React / CSS module —— 调它的那条路径本身可能就是渲染崩了。fail()本身只剩console.error+diagnostics.report(phase, message),上报文案逐字未变。顺带修掉两处 e2e 假绿灯
红条改了 DOM 形状,这两条断言必须同步,否则会从「查红条」变成「永远不查」:
tests/e2e/mount.e2e.ts的assertNoCrash用sidebar.locator('div')(sidebar=[data-dsh-better-sidebar])找红条,而fail()的红条钉在<body>、在 sidebar host 之外 —— 这半条断言从来就匹配不到,等于死的。现拆成两条:RenderBoundary 的红条(仍按dsh-better-sidebar:文本前缀,覆盖面与位置不变)+fail()的红条(按稳定 id)。tests/e2e/native-reload.e2e.ts用body > div+hasText找红条;加了容器后红条变成body > div > div,这条会静默通过(正好与这条 lane 存在的意义相反)。改为按稳定 id 定位,并把原因写在注释里。两个 e2e spec 直接 import 模块导出的 id / 属性常量,避免再出现「DOM 改了、选择器镜像没改」的漂移(e2e spec 首次 import
src/,仅取常量,无运行时依赖)。测试
tests/diagnostic-strip.spec.ts(jsdom,7 例):同 phase 重写不叠加 / 多 phase 共用一个 host / 超上限淘汰最旧 / 逐行关闭且末行移除 host /clear()清空(disposer 路径)/ 采纳上一激活遗留的 host 而不重复 / DOM 抛错时不炸。pnpm typecheck/pnpm lint/pnpm build绿;lib/client.js内含新模块。tests/locales.spec.ts的pluginMneme缺键(zh 有 4 处、ja 有 0 处)—— main 自身的既有红(#822的 i18n 门禁修的就是它),本 PR 未改任何 locale 文件。pnpm build && pnpm pack && pnpm test:mount,宿主钉@deepseek-ai/dsh@0.2.0-rc.1):9 passed (46.6s),含改过选择器的mount.e2e.ts与native-reload.e2e.ts。Closes #767