-
Notifications
You must be signed in to change notification settings - Fork 313
[v1.3] 修正React重绘问题 (Popup) #1181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d4a47f8
1847377
85e69bc
366f79e
9a5b23c
2897ae5
7aa9c29
483aa3e
b99ae0b
3f50d52
d212786
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -41,6 +41,32 @@ const scriptListSorter = (a: ScriptMenu, b: ScriptMenu) => | |||||||||||||||||||||||||||||||
| b.runNum - a.runNum || | ||||||||||||||||||||||||||||||||
| b.updatetime - a.updatetime; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| type TUpdateEntryFn = (item: ScriptMenu) => ScriptMenu | undefined; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| type TUpdateListOption = { sort?: boolean }; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const updateList = (list: ScriptMenu[], update: TUpdateEntryFn, options: TUpdateListOption | undefined) => { | ||||||||||||||||||||||||||||||||
| // 如果更新跟当前 list 的子项无关,则不用更改 list 的物件参考 | ||||||||||||||||||||||||||||||||
| const newList: ScriptMenu[] = []; | ||||||||||||||||||||||||||||||||
| let changed = false; | ||||||||||||||||||||||||||||||||
| for (let i = 0; i < list.length; i++) { | ||||||||||||||||||||||||||||||||
| const oldItem = list[i]; | ||||||||||||||||||||||||||||||||
| const newItem = update(oldItem); // 如没有更改,物件参考会保持一致 | ||||||||||||||||||||||||||||||||
| if (newItem !== oldItem) changed = true; | ||||||||||||||||||||||||||||||||
| if (newItem) { | ||||||||||||||||||||||||||||||||
| newList.push(newItem); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| if (options?.sort) { | ||||||||||||||||||||||||||||||||
| newList.sort(scriptListSorter); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| if (!changed && list.map((e) => e.uuid).join(",") !== newList.map((e) => e.uuid).join(",")) { | ||||||||||||||||||||||||||||||||
| // 单一项未有改变,但因为 sort值改变 而改变了次序 | ||||||||||||||||||||||||||||||||
| changed = true; | ||||||||||||||||||||||||||||||||
|
Comment on lines
+63
to
+65
|
||||||||||||||||||||||||||||||||
| if (!changed && list.map((e) => e.uuid).join(",") !== newList.map((e) => e.uuid).join(",")) { | |
| // 单一项未有改变,但因为 sort值改变 而改变了次序 | |
| changed = true; | |
| if (!changed && options?.sort) { | |
| // 单一项未有改变,但因为 sort值改变 而改变了次序 | |
| if (list.length !== newList.length) { | |
| changed = true; | |
| } else { | |
| for (let i = 0; i < list.length; i++) { | |
| if (list[i].uuid !== newList[i].uuid) { | |
| changed = true; | |
| break; | |
| } | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
太长了。这个 micro optimization 不值得
另外这个对比在 前跟后的sort值不一致 的情况都会起作用
Copilot
AI
Feb 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里新增了 updateList(决定是否复用旧 list 引用、以及排序/删除逻辑),属于影响渲染与状态更新的关键路径;当前 tests/pages/popup/App.test.tsx 只覆盖了基础渲染,未覆盖“无变更时必须保持引用不变 / sort 时顺序变化需触发更新”等场景。建议补充针对该更新策略的测试(可考虑抽到独立 util 后做纯函数单测),避免后续优化回归。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fetchMergedList在scriptDAO.get(uuid)读不到脚本时会把metadata回退成{}并写入cacheMetadata,导致后续即使数据恢复也不会再尝试读取真实 metadata(缓存被“永久”填充)。建议只在成功读取到script时才写入缓存,或缓存undefined以允许后续重试/失效刷新。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对。如果真的发生读取失败,就不要再尝试
不然这个物件参考会改不停