fix(web): 修复 demo 任务详情页旁路提问历史缺失导致的整页崩溃

mock 模式下 GET /api/tasks/<id>/side-questions 无路由,被读兜底当集合返回
[],data.items 为 undefined,旁路 hook 的 merge() 迭代抛 TypeError: t is not
iterable,异常在 setState updater 中经 render 重抛、catch 接不住,整页被错误
边界接管。mock handler 显式返回空旁路历史,sideAPI.history 同时归一化返回值。
This commit is contained in:
Autumn-27 committed 2026-09-14 09:37:08 -04:00
1 parent 90f31577f2
commit f2589ad47c
3 files changed
+19 -1

No files matched your search

BIN
View File
Binary file not shown.
+7
View File
@@ -2092,6 +2092,13 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
};
if (path === "/intercept/judge" && m === "PUT") return { ok: true };
// ── 旁路提问(/btw):demo 无旁路会话 ──
// 必须显式命中:路径以 s 结尾会被下面的读兜底判成集合返回 [],items 就成了 undefined。
if (seg.at(-1) === "side-questions") {
if (m === "GET") return { items: [], current: null, next_cursor: 0, snapshot: null };
if (m === "POST") throw new Error("演示模式不支持旁路提问");
}
// ── 写操作兜底:成功但不落库 ──
if (["POST", "PUT", "PATCH", "DELETE"].includes(m)) return { ok: true };
+12 -1
View File
@@ -41,7 +41,18 @@ async function request<T>(path: string, method = "GET", body?: unknown): Promise
}
export const sideAPI = {
history: (parent: string, before = 0) => request<SideHistory>(`${parent}/side-questions?before=${before}`),
// 历史必须归一化后再交给调用方:items 一旦不是数组,消费端的 setState updater 会抛,
// 而 React 会把 updater 的异常推迟到 render 阶段重抛 —— 那时调用方的 catch 已经够不着,
// 整页直接被错误边界接管。
history: async (parent: string, before = 0) => {
const data = await request<Partial<SideHistory>>(`${parent}/side-questions?before=${before}`);
return {
items: Array.isArray(data?.items) ? data.items : [],
current: data?.current ?? null,
next_cursor: Number(data?.next_cursor) || 0,
snapshot: data?.snapshot ?? null,
} satisfies SideHistory;
},
ask: (parent: string, question: string, client_request_id: string) =>
request<SideExchange>(`${parent}/side-questions`, "POST", { question, client_request_id }),
clear: (parent: string) => request(`${parent}/side-questions`, "DELETE"),