🐛 批量更新页打开更新详情复用检查缓存并挡住重复点击 - #1719
Open
CodFrm wants to merge 1 commit into
Open
Conversation
点击脚本名查看更新时,openUpdatePageByUUID 会重新 fetch 一次脚本代码, 而这份新版代码在检查更新阶段已经存进 scriptUpdateCheck 的记录缓存里 (行内「更新」按钮装的就是它)。用户因此要为每次点击白等一次网络往返, 期间页面又没有任何反馈,连点几下就会开出多个安装页。 - SW: 拆出 prepareUpdateOrInstallPage,openUpdatePage 命中缓存代码时 跳过 fetchScriptBody;openUpdatePageByUUID 改为回报 boolean - 页面: 打开期间行内转圈并同步挡住重复点击,失败弹 toast, 点击脚本名同样取消自动关闭倒计时
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist / 检查清单
N/A — 无关联 issue,问题由维护者在批量更新页直接反馈;
Code reviewed by human待人工审阅。背景
在
src/batchupdate.html上点击脚本名查看更新详情时:读代码定位到根因:检查更新阶段已经把新版代码拉下来存进了
ScriptUpdateCheck的记录缓存(cacheFull.list[].newCode,行内「更新」按钮装的就是这份),但openUpdatePageByUUID→openUpdatePage→openUpdateOrInstallPage第一句仍是await fetchScriptBody(url),为每次点击白跑一次网络往返。而openInCurrentTab实际是chrome.tabs.create,所以点几次就开几个安装页。改前构建上的复现(本地 mock server 记录真实请求,同一 tick 连点 3 次):
本次改动
Service Worker(
src/app/service/service_worker/script.ts)openUpdateOrInstallPage拆成「拉代码」+「处理代码」两段,新增prepareUpdateOrInstallPage;原方法退化为fetchScriptBody后交给它,静默更新判定、SkillScript 分支、临时代码写入逻辑原样保留。openUpdatePage增加可选cachedNewCode:命中时直接进处理段,跳过网络拉取;并改为回报boolean(打开安装页或完成静默更新为true,拉取/解析失败为false)。openUpdatePageByUUID从检查记录缓存取newCode传入,缓存缺失时按原路回退网络拉取;同时用 DAO 取到的完整Script直接传参,去掉原先拼半个对象所需的@ts-ignore。页面(
src/pages/batchupdate/)hooks.ts:新增opening状态与同步镜像openingRef;onOpen在请求进行中拒绝同一行的重复点击,失败(返回false或消息通道 reject)弹notify.error;点击脚本名同样取消自动关闭倒计时。components.tsx/mobile.tsx:ScriptName增加loading,打开期间disabled+aria-busy+ 转圈,桌面与移动两套视图一致。install:updatepage.open_failed,10 个语言包已补齐。实现考虑
prepareUpdateOrInstallPage,静默更新开关命中时仍然返回2、不开安装页。setState是异步的,挡不住同一 tick 内的连击;openingRef同步落地,openingstate 只负责驱动转圈。batchUpdateListAction的更新路径本来也用这份缓存,两者保持一致。已知限制
建议审查重点
prepareUpdateOrInstallPage拆分后,安装(update=false)与更新(update=true)两条既有路径行为是否完全不变。openUpdatePage由void改为boolean后,另一处调用方requestCheckUpdate不受影响。验证
新增测试(均先写后红再实现):
script.test.ts—— 命中缓存不再拉取 / 缓存失效回退拉取 / 拉取失败回报false/ 脚本不存在回报falsehooks.test.ts—— 打开期间标记进行中且重复点击不重复发起 / 失败弹提示并解除转圈 / 消息 reject 同样反馈 / 点击取消自动关闭components.test.tsx—— 桌面行打开期间aria-busy+ 转圈且拒绝点击 / 非打开态可点击 / 移动卡片一致真实浏览器验证(
node e2e/session.mjs+ 本地 mock server,非提交进仓库的用例):已知的既有问题(与本 PR 无关,在干净树上同样失败):
src/pages/install/useInstallData.test.ts有 1 条用例失败。Screenshots / 截图
改动为行内转圈与失败 toast 的交互反馈,主路径修复后打开近乎瞬时,静态截图无法体现差异;上文以 mock server 请求数与标签页数量作为证据。