Skip to content

Commit d83ad0d

Browse files
committed
⚡️ 优化弹出页面重新渲染导致点击后台脚本运行按钮后折叠的问题
1 parent 610fba0 commit d83ad0d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/pages/components/ScriptMenuList/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,18 @@ const ScriptMenuList = React.memo(
356356

357357
ListMenuItem.displayName = "ListMenuItem";
358358

359+
// 使用 useCallback 来缓存渲染函数,避免每次渲染都创建新的函数实例
360+
const renderListItem = useCallback(
361+
({ item, index }: { item: ScriptMenu; index: number }) => (
362+
<ListMenuItem key={`${item.uuid}`} item={item} index={index} />
363+
),
364+
[]
365+
);
366+
359367
return (
360368
<>
361369
{list.length === 0 && <Empty description={t("no_data")} />}
362-
{list.map((item, index) => (
363-
<ListMenuItem key={`${item.uuid}`} item={item} index={index} />
364-
))}
370+
{list.map((item, index) => renderListItem({ item, index }))}
365371
</>
366372
);
367373
}

src/pages/popup/App.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,8 @@ function App() {
202202
// 检查位置,优化窗口过小,导致弹出菜单显示不全的问题
203203
setTimeout(() => {
204204
const dropdowns = document.getElementsByClassName("arco-dropdown");
205-
console.log(dropdowns);
206205
if (dropdowns.length > 0) {
207206
const dropdown = dropdowns[0] as HTMLElement;
208-
console.log(dropdowns, dropdown.style.top);
209207
// 如果top是负数修改为0
210208
if (parseInt(dropdown.style.top) < 0) {
211209
dropdown.style.top = "0px";

0 commit comments

Comments
 (0)