Skip to content

fix(eval-ui): settle detail loading on failure and offer retry (#396) - #420

Closed
wannT-1 wants to merge 1 commit into
helsome:mainfrom
wannT-1:fix/eval-detail-loading-state
Closed

wannT-1 wants to merge 1 commit into
helsome:mainfrom
wannT-1:fix/eval-detail-loading-state

Conversation

@wannT-1

@wannT-1 wannT-1 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

修复 #396:实验/案例详情加载失败后永久转圈,错误与重试都不显示。

根因

父组件把真实的异步结果丢掉了:

  1. EvaluationCenter.loadDetail() 失败时(ok:false,或 ok:true 但 data 为空)只 return null,失败原因未进入任何 React state。
  2. 两个子组件的 onLoadDetail 被包装成 () => void loadDetail(...)。void 让包装函数同步返回 undefined,子组件 await onLoadDetail() 在下一个 microtask 就 resolve,早于 IPC settle —— 真实结果再也传不回来。
  3. 子组件 effect 只 setError(null)、随后 setLoading(false);失败后 detail === null 且 error === null,渲染条件 if (loading || (detail === null && !error)) 恒真 → 永久停在 loading 分支。

CaseDetail 是同一机制的副本。

改动

文件 改动
EvaluationCenter.tsx 去掉 void,恢复 Promise 传递;新增两个按选中 id 稳定的 useCallback loader,避免每次渲染换身份导致子组件 effect 重跑、重复发起 IPC
ExperimentDetail.tsx onLoadDetail 类型改为 () => Promise<EvaluationExperimentDetail | null>;effect await 真实结果,null → 设置可读错误;loading 初值按 detail === null 决定(避免首帧错误闪现);失败分支加 Retry;cleanup 置 cancelled 防止旧请求回填
CaseDetail.tsx 同上(文案用 evaluation.caseError)
evaluation.test.tsx 新增 4 个回归测试:失败、无记录、成功、Retry 重新请求

复用已有 i18n key(evaluation.experimentError / evaluation.caseError / evaluation.retry),en-US 与 zh-CN 均已存在,无需新增。

验证

  • bun test packages/ui/src/components/evaluation/evaluation.test.tsx → 11 pass / 0 fail
  • 回退 3 个源文件、仅保留新测试 → 8 pass / 3 fail(红→绿成立,测试确实锁定该缺陷)
  • tsc --noEmit -p packages/ui/tsconfig.json → exit 0

Fixes #396

@wannT-1

wannT-1 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #401, which implements the same fix (keep the parent→child Promise result, end the loading state on failure, show a Retry action, and guard against stale prefetch overwriting current state) and predates this PR.

Closing this to avoid stacking duplicate fixes on #396. If #401 stalls, I'm happy to rebase this branch (fix/eval-detail-loading-state) and re-open — it carries a red→green regression suite (11 pass with the fix, 3 targeted failures without it) that can be folded in.

@wannT-1 wannT-1 closed this Nov 17, 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.

bug(eval-ui): 实验或案例详情加载失败后永久转圈

1 participant