Repository navigation
v1.0.4 · 修复升级后旧页面被缓存钉住
修一个只在升级后出现、看起来像「注册坏了」的故障。
症状
升级到 1.0.3 后打开页面,右上角弹「读取失败:Cannot read properties of undefined (reading 'map')」,技能列表空白,首登问卷不弹。
原因
不是账号或注册的问题,是浏览器里还留着 1.0.2 的旧页面:
sw.js对页面外壳是缓存优先,且缓存名固定为proficiency-shell-v1,版本升级不会换;- 1.0.2 的页面读
/api/surveys的baseline字段,而 1.0.3 把它改成了baseline_by_skill; - 旧页面向新接口取
baseline得到undefined,再.map就抛这个错——正好发生在弹问卷那一步,所以问卷也没了。
修复
- 页面外壳改为网络优先、离线回退:升级后下一次打开先拿服务器的新页面,旧缓存只作离线兜底。
- 缓存名跟着版本走(
proficiency-shell-1.0.4,由build_ui.py从server.py同步),activate 时删掉旧版本缓存。 - 版本握手:页面注入
window.__APP_VERSION__,启动时与/healthz的version比对;不一致就注销 Service Worker、清壳缓存、重载一次(同一版本只重试一次,不死循环)。以后即使再出现残留旧页面,也会自愈。 baseQuestionsHtml对缺失题库做防御,不再直接.map未定义值。
升级
下载覆盖即可,存档(data/)不受影响。升级后再刷新一次:第一次打开可能还在用旧 Service Worker,刷新后自动换新。急用可在 F12 → Application → Service Workers → Unregister,或清除该站点数据。
验证
- 75 条单测全过(新增
tests/test_ui_version.py:页面版本注入、缓存名与版本一致、外壳网络优先、握手代码存在)。 - 端到端 49 项分技能自评冒烟全过。
- 真实服务端确认
/healthz返回 1.0.4、页面含__APP_VERSION__ = "1.0.4"、/sw.js的缓存名为proficiency-shell-1.0.4。 - 用 Node 复现旧页面(1.0.3)遇新服务端(1.0.4):自动 Unregister → 删缓存 → 重载,顺序正确。
English — Fixes a post-upgrade white-screen: the service worker pinned the old app shell (cache-first, cache name never changed), so the 1.0.2 page asked the 1.0.3 API for baseline and crashed on .map. The shell is now network-first, the cache name tracks the version, and the page compares its __APP_VERSION__ with /healthz — on mismatch it unregisters the worker, clears shell caches, and reloads once.