Skip to content

Commit 87d2611

Browse files
committed
🐛 修复权限确认页 beforeunload 监听器泄漏
- 拆分 useEffect:beforeunload 注册与 getPermissionInfo 请求独立 - 提取命名 handler,在 cleanup 中 removeEventListener - beforeunload effect 只依赖 [uuid],避免语言切换时重复注册 - .gitignore 忽略 .omc 本地开发目录 根据 PR #1328 @cyfung1031 评审意见处理
1 parent 7da1b89 commit 87d2611

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ test-results
4141
playwright-report
4242

4343
superpowers
44+
.omc

src/pages/confirm/App.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ function PermissionConfirmRequest({ uuid }: { uuid: string }) {
2727
}, []);
2828

2929
useEffect(() => {
30-
window.addEventListener("beforeunload", () => {
30+
const handler = () => {
3131
permissionClient.confirm(uuid, {
3232
allow: false,
3333
type: 0,
3434
});
35-
});
35+
};
36+
window.addEventListener("beforeunload", handler, false);
37+
return () => window.removeEventListener("beforeunload", handler, false);
38+
}, [uuid]);
3639

40+
useEffect(() => {
3741
permissionClient
3842
.getPermissionInfo(uuid)
3943
.then((data) => {

0 commit comments

Comments
 (0)