Skip to content

修复第 4 轮(工程质量·前端):i18n、组件抽取、类型归一化与 Low 级前端问题 - #123

Merged
todosdev[bot] merged 2 commits into
mainfrom
tds/conv-01a14a9e-e7a0-7d44-a266-482e892aec31
Oct 18, 2026
Merged

todosdev[bot] merged 2 commits into
mainfrom
tds/conv-01a14a9e-e7a0-7d44-a266-482e892aec31

Conversation

@todosdev

@todosdev todosdev Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • 落地第 4 轮前端工程质量整改:toast 文案全量走 i18n(中英双语)、删除确认弹窗与倒计时魔数抽取、SQLite 0/1 布尔在 API client 层归一化、列表搜索 300ms 防抖、react-query 重试收窄到网络错误/5xx。
  • 补齐会话过期体验:?next= 回跳(仅站内相对路径,防开放重定向)、剪贴板失败提示、会话过期提示只弹一次。
  • 修复 4 处 Low 级问题(过期时间不足 1 小时显示分钟并校验单位、管理员用户页 mutation 中禁用控件、统计页查询参数与前进/后退同步、倒计时按绝对截止时间计算),并给 client refresh 逻辑建立 node --test 单测(零新增依赖)。

Changes

API client(src/api/client.ts)

  • 新增 ApiRequestError(带 status)、NetworkError、SessionExpiredError 错误分类;isRetryableError 只对网络错误与 5xx 返回 true。
  • WireUser/WireLink + normalizeUser/normalizeLink 在 client 边界把 SQLite 0/1 布尔转成 boolean,User/Link 类型同步更新。
  • 会话过期时保留目标路径跳转,transient/网络失败抛 NetworkError。

i18n(src/i18n/locales/en.ts、zh-CN.ts,src/lib/toast.ts)

  • 新增 toast 文案组(中英各 36 条)与 links.*Remaining 过期标签;toastApiError 统一错误 toast 并吞掉会话过期错误,避免按请求重复提示。

组件与 hooks

  • 新增 components/confirm-dialog.tsx 公共删除确认框,替换链接列表 / 管理员链接 / 管理员用户三处。
  • 新增 hooks/use-debounced-value.ts、lib/constants.ts(RESEND_COUNTDOWN_SECONDS、SEARCH_DEBOUNCE_MS)。
  • use-countdown 改为按绝对截止时间计算,后台标签页节流后不漂移。

页面

  • LinksPage / AdminLinksPage / AdminUsersPage / AnalyticsPage:搜索框 300ms 防抖。
  • App.tsx + LoginPage / TwoFactorPage:会话过期与登录链路透传 ?next=(safeNextPath 白名单校验站内相对路径)。
  • AnalyticsPage:linkId/days 由 URL 派生,前进/后退同步。
  • AdminUsersPage:任一 mutation 进行中,该用户的角色/状态/删除控件全部禁用。
  • link-table-cells.tsx:过期显示分钟级标签,复制失败弹 toast。

测试(src/api/client.test.ts、src/lib/utils.test.ts,package.json 加 test 脚本)

  • 25 例:refresh ok/expired/transient、5xx/408/429、单实例去重、双标签页 Web Locks 串行、401 后重试、会话过期仅通知一次、4xx 状态保留、布尔归一化、重试判定正反例、过期单位/分钟显示、next 白名单。

Testing

  • pnpm install --frozen-lockfile、pnpm check、pnpm typecheck、pnpm build 全部通过;pnpm test 25/25。
  • 本地起 wrangler(D1) + Vite,用 headless Chrome(CDP)实测:登录、链接列表(创建/搜索防抖/删除/复制成功与失败)、管理员用户页(创建、mutation 中禁用、删除确认)、统计页前进/后退、忘记密码重发倒计时(600→598)、两步验证页带 next 跳转、会话过期回跳 ?next= 且提示只弹一次、//evil.example 开放重定向被拒、中文界面 toast 与「剩余 30 分钟」标签。全程无未捕获异常。

Todos added 2 commits October 18, 2026 00:24
- FE-Q1: move hardcoded toast copy to i18n with matching en/zh-CN keys.
- FE-Q2: extract shared ConfirmDialog and a RESEND_COUNTDOWN_SECONDS constant.
- FE-Q3: normalize SQLite 0/1 flags to booleans in the API client and update types/usages.
- FE-R4: retry queries only on transport/5xx errors and debounce list search by 300ms.
- FE-R5: keep ?next= through expiry and login (same-origin paths only) and surface clipboard failures.
- FE-C5: minutes for sub-hour expiry plus unit validation, disable admin controls while mutating, sync analytics params with history, count down from an absolute deadline.
- #6: emit the session-expired toast once per expiry instead of once per request.
- BE-Q2 (web): cover refresh outcomes, cross-tab locking and dedup with node:test.

Checkpoint: rOmcynJUsp5cIiDIEfUC5
- FE-R4: classify transport failures as NetworkError and retry only those and 5xx; JSON parse and other program errors no longer retry, with negative tests.
- FE-C5: disable a user's role/status/delete controls whenever any of that user's mutations is pending.
- BE-Q2: verify the cross-tab Web Locks serialization with a shared mutex stub and two separate client module instances.

Checkpoint: 7i4Ry-7qNjOLOsheocbOk
@todosdev
todosdev Bot merged commit b196ef4 into main Oct 18, 2026
4 checks passed
@mapxn
mapxn deleted the tds/conv-01a14a9e-e7a0-7d44-a266-482e892aec31 branch October 18, 2026 08:56
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.

0 participants