修复慢网络下审批后页面显示旧状态:SW API 缓存仅在离线时回退 [09-26-approve-success-state-unchanged]

app-api-runtime 对 /api/me、/api/workflow/tasks*、/api/workflow/approvers*、
/api/notifications* 使用 NetworkFirst + networkTimeoutSeconds: 3。网络响应
超过 3 秒时 Service Worker 返回审批前缓存的旧响应,真实响应被丢弃,页面
仍显示「待派发」。审批写入本身正确。自 2026-03(9112383d)起存在。

去掉网络超时,只在网络失败(离线)时回退缓存;退出登录清理缓存不变。
新增回归测试锁定该规则。负载复现修复前 3 轮命中 2 轮,修复后 3 轮 0 命中。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
这个提交包含在:
2026-09-26 18:58:45 +08:00
共同撰写人 Claude Opus 5.5
父节点 59e20e45cc
当前提交 0931b1ea49
共修改 5 个文件,包含 53 行新增和 8 行删除
@@ -0,0 +1,24 @@
import { readFileSync } from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
const viteConfig = readFileSync(path.resolve(__dirname, "../../../../client/vite.config.ts"), "utf8");
function runtimeCacheRule(cacheName) {
const marker = `cacheName: "${cacheName}"`;
const at = viteConfig.indexOf(marker);
expect(at, `${cacheName} rule must exist`).toBeGreaterThan(-1);
const start = viteConfig.lastIndexOf("urlPattern:", at);
const end = viteConfig.indexOf("urlPattern:", at);
return viteConfig.slice(start, end === -1 ? undefined : end);
}
describe("client PWA API runtime cache", () => {
it("falls back to cached API data only when the network fails, never on a slow response", () => {
const rule = runtimeCacheRule("app-api-runtime");
expect(rule).toContain('handler: "NetworkFirst"');
// A timeout made the service worker answer a post-approval refetch with the
// cached pre-approval task after 3s, so the page kept showing "待派发".
expect(rule).not.toMatch(/networkTimeoutSeconds/);
});
});